浏览代码

LibWeb: Add FormattingState::clone()

This makes a deep copy of a FormattingState.
Andreas Kling 3 年之前
父节点
当前提交
19954dfdf8
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      Userland/Libraries/LibWeb/Layout/FormattingState.h

+ 9 - 0
Userland/Libraries/LibWeb/Layout/FormattingState.h

@@ -66,6 +66,15 @@ struct FormattingState {
 
     void commit();
 
+    FormattingState clone() const
+    {
+        FormattingState new_state;
+        for (auto& it : nodes) {
+            new_state.nodes.set(it.key, make<NodeState>(*it.value));
+        }
+        return new_state;
+    }
+
     NodeState& get_mutable(NodeWithStyleAndBoxModelMetrics const& box)
     {
         return *nodes.ensure(&box, [] { return make<NodeState>(); });