2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-10-15 07:22:41 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/RefPtr.h>
|
2024-11-14 12:01:23 -03:00
|
|
|
#include <LibGC/Ptr.h>
|
2021-10-10 10:56:29 -03:00
|
|
|
#include <LibWeb/CSS/Display.h>
|
2023-02-25 14:42:45 -03:00
|
|
|
#include <LibWeb/CSS/Selector.h>
|
2020-07-26 14:37:56 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
2019-10-15 07:22:41 -03:00
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
namespace Web::Layout {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2020-11-25 16:29:03 -03:00
|
|
|
class TreeBuilder {
|
2019-10-15 07:22:41 -03:00
|
|
|
public:
|
2020-11-25 16:29:03 -03:00
|
|
|
TreeBuilder();
|
2019-10-15 07:22:41 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Layout::Node> build(DOM::Node&);
|
2020-11-26 17:18:34 -03:00
|
|
|
|
|
|
|
|
private:
|
2021-08-05 05:26:09 -03:00
|
|
|
struct Context {
|
|
|
|
|
bool has_svg_root = false;
|
2024-03-28 12:53:27 -03:00
|
|
|
bool layout_top_layer = false;
|
2024-03-26 21:13:16 -03:00
|
|
|
bool layout_svg_mask_or_clip_path = false;
|
2021-08-05 05:26:09 -03:00
|
|
|
};
|
|
|
|
|
|
2023-10-11 13:42:09 -03:00
|
|
|
i32 calculate_list_item_index(DOM::Node&);
|
|
|
|
|
|
2025-01-13 08:23:40 -03:00
|
|
|
void update_layout_tree_before_children(DOM::Node&, GC::Ref<Layout::Node>, Context&, bool element_has_content_visibility_hidden);
|
|
|
|
|
void update_layout_tree_after_children(DOM::Node&, GC::Ref<Layout::Node>, Context&, bool element_has_content_visibility_hidden);
|
2025-02-03 08:23:15 -03:00
|
|
|
void wrap_in_button_layout_tree_if_needed(DOM::Node&, GC::Ref<Layout::Node>);
|
2025-01-13 08:23:40 -03:00
|
|
|
enum class MustCreateSubtree {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
|
|
|
|
void update_layout_tree(DOM::Node&, Context&, MustCreateSubtree);
|
2020-11-26 17:18:34 -03:00
|
|
|
|
2022-04-13 13:44:14 -03:00
|
|
|
void push_parent(Layout::NodeWithStyle& node) { m_ancestor_stack.append(node); }
|
|
|
|
|
void pop_parent() { m_ancestor_stack.take_last(); }
|
2020-11-26 17:18:34 -03:00
|
|
|
|
2023-09-04 13:39:15 -03:00
|
|
|
template<CSS::DisplayInternal, typename Callback>
|
2021-10-06 12:57:44 -03:00
|
|
|
void for_each_in_tree_with_internal_display(NodeWithStyle& root, Callback);
|
|
|
|
|
|
2023-09-04 13:39:15 -03:00
|
|
|
template<CSS::DisplayInside, typename Callback>
|
2021-10-06 12:57:44 -03:00
|
|
|
void for_each_in_tree_with_inside_display(NodeWithStyle& root, Callback);
|
2021-01-07 14:00:51 -03:00
|
|
|
|
|
|
|
|
void fixup_tables(NodeWithStyle& root);
|
|
|
|
|
void remove_irrelevant_boxes(NodeWithStyle& root);
|
|
|
|
|
void generate_missing_child_wrappers(NodeWithStyle& root);
|
2024-11-14 12:01:23 -03:00
|
|
|
Vector<GC::Root<Box>> generate_missing_parents(NodeWithStyle& root);
|
|
|
|
|
void missing_cells_fixup(Vector<GC::Root<Box>> const&);
|
2021-01-07 14:00:51 -03:00
|
|
|
|
2022-10-06 08:10:03 -03:00
|
|
|
enum class AppendOrPrepend {
|
|
|
|
|
Append,
|
|
|
|
|
Prepend,
|
|
|
|
|
};
|
2022-10-06 09:14:16 -03:00
|
|
|
void insert_node_into_inline_or_block_ancestor(Layout::Node&, CSS::Display, AppendOrPrepend);
|
2025-03-20 13:56:46 -03:00
|
|
|
void create_pseudo_element_if_needed(DOM::Element&, CSS::PseudoElement, AppendOrPrepend);
|
2025-01-15 12:37:30 -03:00
|
|
|
void restructure_block_node_in_inline_parent(NodeWithStyleAndBoxModelMetrics&);
|
2022-10-06 08:10:03 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Layout::Node> m_layout_root;
|
|
|
|
|
Vector<GC::Ref<Layout::NodeWithStyle>> m_ancestor_stack;
|
2023-09-18 11:41:17 -03:00
|
|
|
|
|
|
|
|
u32 m_quote_nesting_level { 0 };
|
2019-10-15 07:22:41 -03:00
|
|
|
};
|
2020-03-07 06:27:02 -03:00
|
|
|
|
|
|
|
|
}
|