diff options
-rw-r--r-- | Ladybird/WebContentView.cpp | 5 | ||||
-rw-r--r-- | Ladybird/WebContentView.h | 2 | ||||
-rw-r--r-- | Ladybird/main.cpp | 26 |
3 files changed, 27 insertions, 6 deletions
diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 8d9f99143f..c0fa8a5e4d 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -1055,3 +1055,8 @@ void WebContentView::notify_server_did_get_accessibility_tree(DeprecatedString c { dbgln("TODO: support accessibility tree in Ladybird"); } + +ErrorOr<String> WebContentView::dump_layout_tree() +{ + return String::from_deprecated_string(client().dump_layout_tree()); +} diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h index 903502949b..2572272e2c 100644 --- a/Ladybird/WebContentView.h +++ b/Ladybird/WebContentView.h @@ -94,6 +94,8 @@ public: void show_js_console(); void show_inspector(); + ErrorOr<String> dump_layout_tree(); + Gfx::IntPoint to_content(Gfx::IntPoint) const; Gfx::IntPoint to_widget(Gfx::IntPoint) const; diff --git a/Ladybird/main.cpp b/Ladybird/main.cpp index e87e73dc3b..097bea26e1 100644 --- a/Ladybird/main.cpp +++ b/Ladybird/main.cpp @@ -7,6 +7,7 @@ #include "BrowserWindow.h" #include "Settings.h" #include "Utilities.h" +#include "WebContentView.h" #include <Browser/CookieJar.h> #include <Browser/Database.h> #include <LibCore/ArgsParser.h> @@ -68,13 +69,32 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) StringView raw_url; StringView webdriver_content_ipc_path; + bool dump_layout_tree; Core::ArgsParser args_parser; args_parser.set_general_help("The Ladybird web browser :^)"); args_parser.add_positional_argument(raw_url, "URL to open", "url", Core::ArgsParser::Required::No); args_parser.add_option(webdriver_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path"); + args_parser.add_option(dump_layout_tree, "Dump layout tree and exit", "dump-layout-tree", 'd'); args_parser.parse(arguments); + URL url = raw_url; + if (Core::File::exists(raw_url)) + url = URL::create_with_file_scheme(Core::File::real_path_for(raw_url)); + else if (!url.is_valid()) + url = DeprecatedString::formatted("http://{}", raw_url); + + if (dump_layout_tree) { + WebContentView view({}); + view.on_load_finish = [&](auto&) { + auto dump = view.dump_layout_tree().release_value_but_fixme_should_propagate_errors(); + outln("{}", dump); + _exit(0); + }; + view.load(url); + return app.exec(); + } + auto cookie_jar = TRY(Browser::CookieJar::create(*database)); BrowserWindow window(cookie_jar, webdriver_content_ipc_path); @@ -83,12 +103,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) window.resize(800, 600); window.show(); - URL url = raw_url; - if (Core::File::exists(raw_url)) - url = URL::create_with_file_scheme(Core::File::real_path_for(raw_url)); - else if (!url.is_valid()) - url = DeprecatedString::formatted("http://{}", raw_url); - if (url.is_valid()) window.view().load(url); |