summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-08 23:34:55 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-08 23:36:19 +0100
commitf52ce49a369964fe4b77ba21cd37dd1ba75a02de (patch)
tree55b2a86afa9794f5503fda9a13e507a655a2d6dd
parentcf646badfafc7446a338b13518e5327cdfe585c1 (diff)
downloadserenity-f52ce49a369964fe4b77ba21cd37dd1ba75a02de.zip
LibWeb: Add a simple DumpLayoutTree program
This loads a page and, dumps the layout tree to stdout, and exits.
-rw-r--r--Libraries/LibWeb/DumpLayoutTree/CMakeLists.txt6
-rw-r--r--Libraries/LibWeb/DumpLayoutTree/main.cpp34
2 files changed, 40 insertions, 0 deletions
diff --git a/Libraries/LibWeb/DumpLayoutTree/CMakeLists.txt b/Libraries/LibWeb/DumpLayoutTree/CMakeLists.txt
new file mode 100644
index 0000000000..11a7ce62f5
--- /dev/null
+++ b/Libraries/LibWeb/DumpLayoutTree/CMakeLists.txt
@@ -0,0 +1,6 @@
+set(SOURCES
+ main.cpp
+)
+
+serenity_bin(DumpLayoutTree)
+target_link_libraries(DumpLayoutTree LibWeb)
diff --git a/Libraries/LibWeb/DumpLayoutTree/main.cpp b/Libraries/LibWeb/DumpLayoutTree/main.cpp
new file mode 100644
index 0000000000..5806d4ab39
--- /dev/null
+++ b/Libraries/LibWeb/DumpLayoutTree/main.cpp
@@ -0,0 +1,34 @@
+#include <LibCore/ArgsParser.h>
+#include <LibGUI/Application.h>
+#include <LibWeb/Dump.h>
+#include <LibWeb/InProcessWebView.h>
+#include <LibWeb/Layout/InitialContainingBlockBox.h>
+#include <stdlib.h>
+
+int main(int argc, char** argv)
+{
+ auto app = GUI::Application::construct(argc, argv);
+ auto window = GUI::Window::construct();
+ window->set_title("DumpLayoutTree");
+ window->resize(800, 600);
+ window->show();
+ auto& web_view = window->set_main_widget<Web::InProcessWebView>();
+ 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());
+ _exit(0);
+ };
+ return app->exec();
+}