test.cpp 803 B

12345678910111213141516171819202122232425262728293031
  1. #include <LibCore/CFile.h>
  2. #include <LibHTML/Dump.h>
  3. #include <LibHTML/Frame.h>
  4. #include <LibHTML/Parser/Parser.h>
  5. #include <stdio.h>
  6. int main(int argc, char** argv)
  7. {
  8. CFile f(argc == 1 ? "/home/anon/small.html" : argv[1]);
  9. if (!f.open(CIODevice::ReadOnly)) {
  10. fprintf(stderr, "Error: %s\n", f.error_string());
  11. return 1;
  12. }
  13. String html = String::copy(f.read_all());
  14. auto doc = parse(html);
  15. dump_tree(doc);
  16. doc->build_layout_tree();
  17. ASSERT(doc->layout_node());
  18. printf("\033[33;1mLayout tree before layout:\033[0m\n");
  19. dump_tree(*doc->layout_node());
  20. auto frame = make<Frame>();
  21. frame->set_document(doc);
  22. frame->layout();
  23. printf("\033[33;1mLayout tree after layout:\033[0m\n");
  24. dump_tree(*doc->layout_node());
  25. return 0;
  26. }