TreeBuilder.h 1.8 KB

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