TreeBuilder.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullRefPtrVector.h>
  8. #include <AK/RefPtr.h>
  9. #include <LibWeb/CSS/Display.h>
  10. #include <LibWeb/Forward.h>
  11. namespace Web::Layout {
  12. class TreeBuilder {
  13. public:
  14. TreeBuilder();
  15. RefPtr<Layout::Node> build(DOM::Node&);
  16. private:
  17. struct Context {
  18. bool has_svg_root = false;
  19. };
  20. void create_layout_tree(DOM::Node&, Context&);
  21. void push_parent(Layout::NodeWithStyle& node) { m_parent_stack.append(&node); }
  22. void pop_parent() { m_parent_stack.take_last(); }
  23. template<CSS::Display::Internal, typename Callback>
  24. void for_each_in_tree_with_internal_display(NodeWithStyle& root, Callback);
  25. template<CSS::Display::Inside, typename Callback>
  26. void for_each_in_tree_with_inside_display(NodeWithStyle& root, Callback);
  27. void fixup_tables(NodeWithStyle& root);
  28. void remove_irrelevant_boxes(NodeWithStyle& root);
  29. void generate_missing_child_wrappers(NodeWithStyle& root);
  30. void generate_missing_parents(NodeWithStyle& root);
  31. RefPtr<Layout::Node> m_layout_root;
  32. Vector<Layout::NodeWithStyle*> m_parent_stack;
  33. };
  34. }