瀏覽代碼

WebContent: Use outerHTML to copy a DOM node's HTML in the Inspector

We can use outerHTML now instead of cloning the node into a temporary
container and invoking the container's innerHTML.
Timothy Flynn 1 年之前
父節點
當前提交
12b3332d3c
共有 1 個文件被更改,包括 11 次插入4 次删除
  1. 11 4
      Userland/Services/WebContent/ConnectionFromClient.cpp

+ 11 - 4
Userland/Services/WebContent/ConnectionFromClient.cpp

@@ -745,11 +745,18 @@ void ConnectionFromClient::get_dom_node_html(u64 page_id, i32 node_id)
     if (!dom_node)
         return;
 
-    // FIXME: Implement Element's outerHTML attribute.
-    auto container = Web::DOM::create_element(dom_node->document(), Web::HTML::TagNames::div, Web::Namespace::HTML).release_value_but_fixme_should_propagate_errors();
-    container->append_child(dom_node->clone_node(nullptr, true)).release_value_but_fixme_should_propagate_errors();
+    String html;
+
+    if (dom_node->is_element()) {
+        auto const& element = static_cast<Web::DOM::Element const&>(*dom_node);
+        html = element.outer_html().release_value_but_fixme_should_propagate_errors();
+    } else if (dom_node->is_text() || dom_node->is_comment()) {
+        auto const& character_data = static_cast<Web::DOM::CharacterData const&>(*dom_node);
+        html = character_data.data();
+    } else {
+        return;
+    }
 
-    auto html = container->inner_html().release_value_but_fixme_should_propagate_errors();
     async_did_get_dom_node_html(page_id, move(html));
 }