LibWeb: Support CSS content property images (and lists, too!)

This patch expands our generated content support beyond single strings
to lists of strings and/or images.

Pseudo-elements like ::before and ::after can now use content:url(...)
to insert anonymous image boxes into the layout tree.

This is heavily used in Google Docs for UI elements.
This commit is contained in:
Andreas Kling 2025-07-27 15:55:16 +02:00 committed by Andreas Kling
commit 81d4079c12
Notes: github-actions[bot] 2025-07-28 20:48:00 +00:00
16 changed files with 494 additions and 99 deletions

View file

@ -2926,10 +2926,14 @@ ErrorOr<String> Node::name_or_description(NameOrDescription target, Document con
// content of the current node. NOTE: The code for handling the ::after pseudo elements case is further below,
// following the “iii. For each child node of the current node” code.
if (auto before = element->get_pseudo_element_node(CSS::PseudoElement::Before)) {
if (before->computed_values().content().alt_text.has_value())
if (before->computed_values().content().alt_text.has_value()) {
total_accumulated_text.append(before->computed_values().content().alt_text.release_value());
else
total_accumulated_text.append(before->computed_values().content().data);
} else {
for (auto& item : before->computed_values().content().data) {
if (auto const* string = item.get_pointer<String>())
total_accumulated_text.append(*string);
}
}
}
// iii. Determine Child Nodes: Determine the rendered child nodes of the current node:
@ -2982,10 +2986,14 @@ ErrorOr<String> Node::name_or_description(NameOrDescription target, Document con
// NOTE: See step ii.b above.
if (auto after = element->get_pseudo_element_node(CSS::PseudoElement::After)) {
if (after->computed_values().content().alt_text.has_value())
if (after->computed_values().content().alt_text.has_value()) {
total_accumulated_text.append(after->computed_values().content().alt_text.release_value());
else
total_accumulated_text.append(after->computed_values().content().data);
} else {
for (auto& item : after->computed_values().content().data) {
if (auto const* string = item.get_pointer<String>())
total_accumulated_text.append(*string);
}
}
}
// v. Return the accumulated text if it is not the empty string ("").