main.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <LibCore/ArgsParser.h>
  27. #include <LibGUI/Application.h>
  28. #include <LibGUI/Window.h>
  29. #include <LibWeb/Dump.h>
  30. #include <LibWeb/InProcessWebView.h>
  31. #include <LibWeb/Layout/InitialContainingBlockBox.h>
  32. #include <unistd.h>
  33. int main(int argc, char** argv)
  34. {
  35. auto app = GUI::Application::construct(argc, argv);
  36. auto window = GUI::Window::construct();
  37. window->set_title("DumpLayoutTree");
  38. window->resize(800, 600);
  39. window->show();
  40. auto& web_view = window->set_main_widget<Web::InProcessWebView>();
  41. web_view.load(URL::create_with_file_protocol(argv[1]));
  42. web_view.on_load_finish = [&](auto&) {
  43. auto* document = web_view.document();
  44. if (!document) {
  45. warnln("No document.");
  46. _exit(1);
  47. }
  48. auto* layout_root = document->layout_node();
  49. if (!layout_root) {
  50. warnln("No layout tree.");
  51. _exit(1);
  52. }
  53. StringBuilder builder;
  54. Web::dump_tree(builder, *layout_root);
  55. write(STDOUT_FILENO, builder.string_view().characters_without_null_termination(), builder.length());
  56. _exit(0);
  57. };
  58. return app->exec();
  59. }