TreeBuilder.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. i32 calculate_list_item_index(DOM::Node&);
  22. ErrorOr<void> create_layout_tree(DOM::Node&, Context&);
  23. void push_parent(Layout::NodeWithStyle& node) { m_ancestor_stack.append(node); }
  24. void pop_parent() { m_ancestor_stack.take_last(); }
  25. template<CSS::DisplayInternal, typename Callback>
  26. void for_each_in_tree_with_internal_display(NodeWithStyle& root, Callback);
  27. template<CSS::DisplayInside, typename Callback>
  28. void for_each_in_tree_with_inside_display(NodeWithStyle& root, Callback);
  29. void fixup_tables(NodeWithStyle& root);
  30. void remove_irrelevant_boxes(NodeWithStyle& root);
  31. void generate_missing_child_wrappers(NodeWithStyle& root);
  32. Vector<JS::Handle<Box>> generate_missing_parents(NodeWithStyle& root);
  33. void missing_cells_fixup(Vector<JS::Handle<Box>> const&);
  34. enum class AppendOrPrepend {
  35. Append,
  36. Prepend,
  37. };
  38. void insert_node_into_inline_or_block_ancestor(Layout::Node&, CSS::Display, AppendOrPrepend);
  39. ErrorOr<void> create_pseudo_element_if_needed(DOM::Element&, CSS::Selector::PseudoElement::Type, AppendOrPrepend);
  40. JS::GCPtr<Layout::Node> m_layout_root;
  41. Vector<JS::NonnullGCPtr<Layout::NodeWithStyle>> m_ancestor_stack;
  42. u32 m_quote_nesting_level { 0 };
  43. };
  44. }