From 777b4f7921a58f4b13d329ad458268da5370e519 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 5 Dec 2023 14:59:54 -0500 Subject: [PATCH] LibWebView+WebContent: Add a WebContent IPC to remove a DOM node The FIXME added to ConnectionFromClient::remove_dom_node is copied from Web::EditEventHandler. The same behavior is observed here, with many lingering Layout::TextNodes, for example. --- .../LibWebView/ViewImplementation.cpp | 5 +++++ .../Libraries/LibWebView/ViewImplementation.h | 1 + .../WebContent/ConnectionFromClient.cpp | 18 ++++++++++++++++++ .../Services/WebContent/ConnectionFromClient.h | 1 + .../Services/WebContent/WebContentServer.ipc | 1 + 5 files changed, 26 insertions(+) diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index 8beef56bbe5..8e8a71ba499 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -201,6 +201,11 @@ void ViewImplementation::replace_dom_node_attribute(i32 node_id, String name, Ve client().async_replace_dom_node_attribute(node_id, move(name), move(replacement_attributes)); } +void ViewImplementation::remove_dom_node(i32 node_id) +{ + client().async_remove_dom_node(node_id); +} + void ViewImplementation::debug_request(DeprecatedString const& request, DeprecatedString const& argument) { client().async_debug_request(request, argument); diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 90ddfbb09c4..aa3cd19082d 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -67,6 +67,7 @@ public: Optional set_dom_node_tag(i32 node_id, String name); void add_dom_node_attributes(i32 node_id, Vector attributes); void replace_dom_node_attribute(i32 node_id, String name, Vector replacement_attributes); + void remove_dom_node(i32 node_id); void debug_request(DeprecatedString const& request, DeprecatedString const& argument = {}); diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index d0f205c7f5a..0e142e8bf1b 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -711,6 +711,24 @@ void ConnectionFromClient::replace_dom_node_attribute(i32 node_id, String const& element.set_attribute(attribute.name, attribute.value).release_value_but_fixme_should_propagate_errors(); } +void ConnectionFromClient::remove_dom_node(i32 node_id) +{ + auto* active_document = page().page().top_level_browsing_context().active_document(); + if (!active_document) + return; + + auto* dom_node = Web::DOM::Node::from_unique_id(node_id); + if (!dom_node) + return; + + dom_node->remove(); + + // FIXME: When nodes are removed from the DOM, the associated layout nodes become stale and still + // remain in the layout tree. This has to be fixed, this just causes everything to be recomputed + // which really hurts performance. + active_document->force_layout(); +} + void ConnectionFromClient::initialize_js_console(Badge, Web::DOM::Document& document) { auto& realm = document.realm(); diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index 906bb9c89c4..e74fdaeae04 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -80,6 +80,7 @@ private: virtual Messages::WebContentServer::SetDomNodeTagResponse set_dom_node_tag(i32 node_id, String const& name) override; virtual void add_dom_node_attributes(i32 node_id, Vector const& attributes) override; virtual void replace_dom_node_attribute(i32 node_id, String const& name, Vector const& replacement_attributes) override; + virtual void remove_dom_node(i32 node_id) override; virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override; virtual Messages::WebContentServer::DumpPaintTreeResponse dump_paint_tree() override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index 28faeae0b00..3ef342dc482 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -50,6 +50,7 @@ endpoint WebContentServer set_dom_node_tag(i32 node_id, String name) => (Optional node_id) add_dom_node_attributes(i32 node_id, Vector attributes) =| replace_dom_node_attribute(i32 node_id, String name, Vector replacement_attributes) =| + remove_dom_node(i32 node_id) =| take_document_screenshot() => (Gfx::ShareableBitmap data)