main.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibCore/ArgsParser.h>
  7. #include <LibGUI/Application.h>
  8. #include <LibGUI/Window.h>
  9. #include <LibWeb/Dump.h>
  10. #include <LibWeb/InProcessWebView.h>
  11. #include <LibWeb/Layout/InitialContainingBlockBox.h>
  12. #include <unistd.h>
  13. int main(int argc, char** argv)
  14. {
  15. auto app = GUI::Application::construct(argc, argv);
  16. auto window = GUI::Window::construct();
  17. window->set_title("DumpLayoutTree");
  18. window->resize(800, 600);
  19. window->show();
  20. auto& web_view = window->set_main_widget<Web::InProcessWebView>();
  21. web_view.load(URL::create_with_file_protocol(argv[1]));
  22. web_view.on_load_finish = [&](auto&) {
  23. auto* document = web_view.document();
  24. if (!document) {
  25. warnln("No document.");
  26. _exit(1);
  27. }
  28. auto* layout_root = document->layout_node();
  29. if (!layout_root) {
  30. warnln("No layout tree.");
  31. _exit(1);
  32. }
  33. StringBuilder builder;
  34. Web::dump_tree(builder, *layout_root);
  35. write(STDOUT_FILENO, builder.string_view().characters_without_null_termination(), builder.length());
  36. _exit(0);
  37. };
  38. return app->exec();
  39. }