TreeBuilder.h 1.7 KB

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