فهرست منبع

LibWeb: Add naive layout for SVG foreign objects

We now layout foreign objects as if they form a nested block formatting
context. This probably isn't the most correct way to do this, but it's
a start.
Andreas Kling 2 سال پیش
والد
کامیت
4aeb1ffc12
2فایلهای تغییر یافته به همراه18 افزوده شده و 0 حذف شده
  1. 15 0
      Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp
  2. 3 0
      Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp

+ 15 - 0
Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp

@@ -7,8 +7,10 @@
  */
  */
 
 
 #include <AK/Format.h>
 #include <AK/Format.h>
+#include <LibWeb/Layout/BlockFormattingContext.h>
 #include <LibWeb/Layout/SVGFormattingContext.h>
 #include <LibWeb/Layout/SVGFormattingContext.h>
 #include <LibWeb/Layout/SVGGeometryBox.h>
 #include <LibWeb/Layout/SVGGeometryBox.h>
+#include <LibWeb/SVG/SVGForeignObjectElement.h>
 #include <LibWeb/SVG/SVGSVGElement.h>
 #include <LibWeb/SVG/SVGSVGElement.h>
 
 
 namespace Web::Layout {
 namespace Web::Layout {
@@ -31,6 +33,19 @@ void SVGFormattingContext::run(Box const& box, LayoutMode, [[maybe_unused]] Avai
 
 
     auto& svg_svg_element = verify_cast<SVG::SVGSVGElement>(*box.dom_node());
     auto& svg_svg_element = verify_cast<SVG::SVGSVGElement>(*box.dom_node());
 
 
+    auto root_offset = m_state.get(box).offset;
+
+    box.for_each_child_of_type<BlockContainer>([&](BlockContainer const& child_box) {
+        if (is<SVG::SVGForeignObjectElement>(child_box.dom_node())) {
+            Layout::BlockFormattingContext bfc(m_state, child_box, this);
+            bfc.run(child_box, LayoutMode::Normal, available_space);
+
+            auto& child_state = m_state.get_mutable(child_box);
+            child_state.set_content_offset(child_state.offset.translated(root_offset));
+        }
+        return IterationDecision::Continue;
+    });
+
     box.for_each_in_subtree_of_type<SVGBox>([&](SVGBox const& descendant) {
     box.for_each_in_subtree_of_type<SVGBox>([&](SVGBox const& descendant) {
         if (is<SVGGeometryBox>(descendant)) {
         if (is<SVGGeometryBox>(descendant)) {
             auto const& geometry_box = static_cast<SVGGeometryBox const&>(descendant);
             auto const& geometry_box = static_cast<SVGGeometryBox const&>(descendant);

+ 3 - 0
Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp

@@ -24,6 +24,7 @@
 #include <LibWeb/Layout/TableRowBox.h>
 #include <LibWeb/Layout/TableRowBox.h>
 #include <LibWeb/Layout/TextNode.h>
 #include <LibWeb/Layout/TextNode.h>
 #include <LibWeb/Layout/TreeBuilder.h>
 #include <LibWeb/Layout/TreeBuilder.h>
+#include <LibWeb/SVG/SVGForeignObjectElement.h>
 
 
 namespace Web::Layout {
 namespace Web::Layout {
 
 
@@ -130,6 +131,8 @@ void TreeBuilder::insert_node_into_inline_or_block_ancestor(Layout::Node& node,
                     return ancestor;
                     return ancestor;
                 if (!ancestor.display().is_flow_inside())
                 if (!ancestor.display().is_flow_inside())
                     return ancestor;
                     return ancestor;
+                if (ancestor.dom_node() && is<SVG::SVGForeignObjectElement>(*ancestor.dom_node()))
+                    return ancestor;
             }
             }
             VERIFY_NOT_REACHED();
             VERIFY_NOT_REACHED();
         }();
         }();