layout: Fix display of new text in textarea elements (#32886)

Previously `<textarea>` was just displaying node contents, which is the
original text content, not the one updated by later typing. This change
fixes that issue.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-07-30 16:39:17 +02:00 committed by GitHub
parent c06a6a764e
commit a64f75b62f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 30 additions and 31 deletions

View file

@ -169,32 +169,43 @@ fn traverse_children_of<'dom, Node>(
{
traverse_pseudo_element(WhichPseudoElement::Before, parent_element, context, handler);
for child in iter_child_nodes(parent_element) {
if child.is_text_node() {
let info = NodeAndStyleInfo::new(child, child.style(context));
handler.handle_text(&info, child.to_threadsafe().node_text_content());
} else if child.is_element() {
traverse_element(child, context, handler);
}
}
if matches!(
let is_text_input_element = matches!(
parent_element.type_id(),
LayoutNodeType::Element(LayoutElementType::HTMLInputElement)
) {
);
let is_textarea_element = matches!(
parent_element.type_id(),
LayoutNodeType::Element(LayoutElementType::HTMLTextAreaElement)
);
if is_text_input_element || is_textarea_element {
let info = NodeAndStyleInfo::new(parent_element, parent_element.style(context));
// The addition of zero-width space here forces the text input to have an inline formatting
// context that might otherwise be trimmed if there's no text. This is important to ensure
// that the input element is at least as tall as the line gap of the caret:
// <https://drafts.csswg.org/css-ui/#element-with-default-preferred-size>.
//
// TODO: Is there a less hacky way to do this?
handler.handle_text(&info, "\u{200B}".into());
if is_text_input_element {
// The addition of zero-width space here forces the text input to have an inline formatting
// context that might otherwise be trimmed if there's no text. This is important to ensure
// that the input element is at least as tall as the line gap of the caret:
// <https://drafts.csswg.org/css-ui/#element-with-default-preferred-size>.
//
// TODO: Is there a less hacky way to do this?
handler.handle_text(&info, "\u{200B}".into());
}
handler.handle_text(&info, parent_element.to_threadsafe().node_text_content());
}
if !is_text_input_element && !is_textarea_element {
for child in iter_child_nodes(parent_element) {
if child.is_text_node() {
let info = NodeAndStyleInfo::new(child, child.style(context));
handler.handle_text(&info, child.to_threadsafe().node_text_content());
} else if child.is_element() {
traverse_element(child, context, handler);
}
}
}
traverse_pseudo_element(WhichPseudoElement::After, parent_element, context, handler);
}

View file

@ -5,5 +5,5 @@
[.target > * 1]
expected: FAIL
[.target > * 5]
[.target > * 11]
expected: FAIL

View file

@ -1,2 +0,0 @@
[dir_auto-textarea-script-N-EN.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[multiline-placeholder-cr.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[multiline-placeholder-crlf.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[multiline-placeholder.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[placeholder-white-space.tentative.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[textarea_placeholder.html]
expected: FAIL