Browse Source

LibWeb: Create paintables for nodes whose parents don't have paintables

A Paintable is not created for an SVG <defs> element (nor should it),
but it can contain SVG <mask> elements that need a paintable.

This change forces those paintables to be created (without a parent).
The masks are then only painted by being referenced from another
element.
MacDue 1 year ago
parent
commit
c5b50ec2f4
1 changed files with 11 additions and 10 deletions
  1. 11 10
      Userland/Libraries/LibWeb/Layout/LayoutState.cpp

+ 11 - 10
Userland/Libraries/LibWeb/Layout/LayoutState.cpp

@@ -198,18 +198,19 @@ void LayoutState::resolve_relative_positions(Vector<Painting::PaintableWithLines
 
 static void build_paint_tree(Node& node, Painting::Paintable* parent_paintable = nullptr)
 {
-    if (!node.paintable())
-        return;
-    auto& paintable = const_cast<Painting::Paintable&>(*node.paintable());
-    if (parent_paintable) {
-        VERIFY(!paintable.parent());
-        parent_paintable->append_child(paintable);
+    Painting::Paintable* paintable = nullptr;
+    if (node.paintable()) {
+        paintable = const_cast<Painting::Paintable*>(node.paintable());
+        if (parent_paintable) {
+            VERIFY(!paintable->parent());
+            parent_paintable->append_child(*paintable);
+        }
+        paintable->set_dom_node(node.dom_node());
+        if (node.dom_node())
+            node.dom_node()->set_paintable(paintable);
     }
-    paintable.set_dom_node(node.dom_node());
-    if (node.dom_node())
-        node.dom_node()->set_paintable(&paintable);
     for (auto* child = node.first_child(); child; child = child->next_sibling()) {
-        build_paint_tree(*child, &paintable);
+        build_paint_tree(*child, paintable);
     }
 }