TreeBuilder.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_ancestor_stack.append(node); }
  22. void pop_parent() { m_ancestor_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. enum class AppendOrPrepend {
  32. Append,
  33. Prepend,
  34. };
  35. void insert_node_into_inline_or_block_ancestor(Layout::Node&, CSS::Display, AppendOrPrepend);
  36. void create_pseudo_element_if_needed(DOM::Element&, CSS::Selector::PseudoElement, AppendOrPrepend);
  37. RefPtr<Layout::Node> m_layout_root;
  38. Vector<Layout::NodeWithStyle&> m_ancestor_stack;
  39. };
  40. }