Truly independent web browser
LibWeb: Serialize box-less white space text of a rendered element
Aliaksandr Kalenik710ee828e735
diff --git a/Libraries/LibWeb/DOM/Range.cpp b/Libraries/LibWeb/DOM/Range.cppindex be0cd38abdd..0a13e194c2f 100644--- a/Libraries/LibWeb/DOM/Range.cpp+++ b/Libraries/LibWeb/DOM/Range.cpp@@ -1378,11 +1378,10 @@ Vector<Gfx::DoubleRect> Range::client_rects()if (selection_state == Painting::SelectionState::None)continue;+ // A text node without a box renders nothing, so it has no rects.auto const* layout_node = text.layout_node(read);- if (!layout_node) {- dbgln("FIXME: Failed to get client rects for node {}", node->debug_description());+ if (!layout_node)continue;- }if (!visual_context_tree.has_value() && !document.can_compute_client_rects_without_accumulated_visual_contexts_update(*layout_node)) {document.update_paint_and_hit_testing_properties_if_needed();diff --git a/Libraries/LibWeb/Editing/StyledMarkupAccumulator.cpp b/Libraries/LibWeb/Editing/StyledMarkupAccumulator.cppindex ce8fde50036..9d08b04f236 100644--- a/Libraries/LibWeb/Editing/StyledMarkupAccumulator.cpp+++ b/Libraries/LibWeb/Editing/StyledMarkupAccumulator.cpp@@ -27,6 +27,13 @@ static bool should_serialize_node(DOM::Node const& node)if (node.has_layout_box())return true;+ // White space that renders nothing has no box, but it is part of the markup of the element around it like the+ // rest of the element's text. Text that renders nothing is dropped once the fragment is built.+ if (auto const* text = as_if<DOM::Text>(node); text && text->data().is_ascii_whitespace()) {+ auto parent = text->parent_element();+ return parent && should_serialize_node(*parent);+ }+auto const* element = as_if<DOM::Element>(node);auto const* box_values = element ? element->style_group<CSS::ComputedValues::BoxValues>() : nullptr;return box_values && CSS::display_from_ffi_display(box_values->display).is_contents();