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.
This commit is contained in:
Timothy Flynn 2023-12-05 14:59:54 -05:00 committed by Andreas Kling
parent 86d90f324d
commit 777b4f7921
Notes: sideshowbarker 2024-07-17 06:29:49 +09:00
5 changed files with 26 additions and 0 deletions

View File

@ -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);

View File

@ -67,6 +67,7 @@ public:
Optional<i32> set_dom_node_tag(i32 node_id, String name);
void add_dom_node_attributes(i32 node_id, Vector<Attribute> attributes);
void replace_dom_node_attribute(i32 node_id, String name, Vector<Attribute> replacement_attributes);
void remove_dom_node(i32 node_id);
void debug_request(DeprecatedString const& request, DeprecatedString const& argument = {});

View File

@ -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<PageClient>, Web::DOM::Document& document)
{
auto& realm = document.realm();

View File

@ -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<WebView::Attribute> const& attributes) override;
virtual void replace_dom_node_attribute(i32 node_id, String const& name, Vector<WebView::Attribute> 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;

View File

@ -50,6 +50,7 @@ endpoint WebContentServer
set_dom_node_tag(i32 node_id, String name) => (Optional<i32> node_id)
add_dom_node_attributes(i32 node_id, Vector<WebView::Attribute> attributes) =|
replace_dom_node_attribute(i32 node_id, String name, Vector<WebView::Attribute> replacement_attributes) =|
remove_dom_node(i32 node_id) =|
take_document_screenshot() => (Gfx::ShareableBitmap data)