LibWeb+WebContent: Port DumpLayoutTree to OutOfProcessWebView

This required adding a simple OOPWV::dump_layout_tree() API that
synchronously requests a dump of the layout tree from the WebContent
process.
This commit is contained in:
Andreas Kling 2021-09-08 00:55:35 +02:00
parent c6e56612f5
commit 9d03ea6f74
Notes: sideshowbarker 2024-07-18 04:27:32 +09:00
6 changed files with 28 additions and 18 deletions

View file

@ -7,9 +7,7 @@
#include <LibCore/ArgsParser.h>
#include <LibGUI/Application.h>
#include <LibGUI/Window.h>
#include <LibWeb/Dump.h>
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/OutOfProcessWebView.h>
#include <unistd.h>
int main(int argc, char** argv)
@ -19,22 +17,11 @@ int main(int argc, char** argv)
window->set_title("DumpLayoutTree");
window->resize(800, 600);
window->show();
auto& web_view = window->set_main_widget<Web::InProcessWebView>();
auto& web_view = window->set_main_widget<Web::OutOfProcessWebView>();
web_view.load(URL::create_with_file_protocol(argv[1]));
web_view.on_load_finish = [&](auto&) {
auto* document = web_view.document();
if (!document) {
warnln("No document.");
_exit(1);
}
auto* layout_root = document->layout_node();
if (!layout_root) {
warnln("No layout tree.");
_exit(1);
}
StringBuilder builder;
Web::dump_tree(builder, *layout_root);
write(STDOUT_FILENO, builder.string_view().characters_without_null_termination(), builder.length());
auto dump = web_view.dump_layout_tree();
write(STDOUT_FILENO, dump.characters(), dump.length() + 1);
_exit(0);
};
return app->exec();

View file

@ -460,4 +460,9 @@ void OutOfProcessWebView::select_all()
client().async_select_all();
}
String OutOfProcessWebView::dump_layout_tree()
{
return client().dump_layout_tree();
}
}

View file

@ -49,6 +49,8 @@ public:
String selected_text();
void select_all();
String dump_layout_tree();
void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size);
void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id);
void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, const Gfx::IntRect&);

View file

@ -321,4 +321,17 @@ void ClientConnection::select_all()
page().client().page_did_change_selection();
}
Messages::WebContentServer::DumpLayoutTreeResponse ClientConnection::dump_layout_tree()
{
auto* document = page().top_level_browsing_context().document();
if (!document)
return String { "(no DOM tree)" };
auto* layout_root = document->layout_node();
if (!layout_root)
return String { "(no layout tree)" };
StringBuilder builder;
Web::dump_tree(builder, *layout_root);
return builder.to_string();
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -54,6 +54,7 @@ private:
virtual void inspect_dom_tree() override;
virtual Messages::WebContentServer::InspectDomNodeResponse inspect_dom_node(i32) override;
virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override;
virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override;
virtual void js_console_input(String const&) override;
virtual void run_javascript(String const&) override;

View file

@ -34,6 +34,8 @@ endpoint WebContentServer
run_javascript(String js_source) =|
dump_layout_tree() => (String dump)
get_selected_text() => (String selection)
select_all() =|
}