TreeBuilder.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/RefPtr.h>
  8. #include <LibJS/Heap/GCPtr.h>
  9. #include <LibWeb/CSS/Display.h>
  10. #include <LibWeb/CSS/Selector.h>
  11. #include <LibWeb/Forward.h>
  12. namespace Web::Layout {
  13. class TreeBuilder {
  14. public:
  15. TreeBuilder();
  16. JS::GCPtr<Layout::Node> build(DOM::Node&);
  17. private:
  18. struct Context {
  19. bool has_svg_root = false;
  20. };
  21. ErrorOr<void> create_layout_tree(DOM::Node&, Context&);
  22. void push_parent(Layout::NodeWithStyle& node) { m_ancestor_stack.append(node); }
  23. void pop_parent() { m_ancestor_stack.take_last(); }
  24. template<CSS::Display::Internal, typename Callback>
  25. void for_each_in_tree_with_internal_display(NodeWithStyle& root, Callback);
  26. template<CSS::Display::Inside, typename Callback>
  27. void for_each_in_tree_with_inside_display(NodeWithStyle& root, Callback);
  28. void fixup_tables(NodeWithStyle& root);
  29. void remove_irrelevant_boxes(NodeWithStyle& root);
  30. void generate_missing_child_wrappers(NodeWithStyle& root);
  31. void generate_missing_parents(NodeWithStyle& root);
  32. enum class AppendOrPrepend {
  33. Append,
  34. Prepend,
  35. };
  36. void insert_node_into_inline_or_block_ancestor(Layout::Node&, CSS::Display, AppendOrPrepend);
  37. ErrorOr<void> create_pseudo_element_if_needed(DOM::Element&, CSS::Selector::PseudoElement, AppendOrPrepend);
  38. JS::GCPtr<Layout::Node> m_layout_root;
  39. Vector<JS::NonnullGCPtr<Layout::NodeWithStyle>> m_ancestor_stack;
  40. };
  41. }