2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-10-15 12:22:41 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/RefPtr.h>
|
2023-02-25 10:42:45 -07:00
|
|
|
#include <LibJS/Heap/GCPtr.h>
|
2021-10-10 15:56:29 +02:00
|
|
|
#include <LibWeb/CSS/Display.h>
|
2023-02-25 10:42:45 -07:00
|
|
|
#include <LibWeb/CSS/Selector.h>
|
2020-07-26 19:37:56 +02:00
|
|
|
#include <LibWeb/Forward.h>
|
2019-10-15 12:22:41 +02:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
namespace Web::Layout {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2020-11-25 20:29:03 +01:00
|
|
|
class TreeBuilder {
|
2019-10-15 12:22:41 +02:00
|
|
|
public:
|
2020-11-25 20:29:03 +01:00
|
|
|
TreeBuilder();
|
2019-10-15 12:22:41 +02:00
|
|
|
|
2022-10-17 14:41:50 +02:00
|
|
|
JS::GCPtr<Layout::Node> build(DOM::Node&);
|
2020-11-26 21:18:34 +01:00
|
|
|
|
|
|
|
private:
|
2021-08-05 10:26:09 +02:00
|
|
|
struct Context {
|
|
|
|
bool has_svg_root = false;
|
|
|
|
};
|
|
|
|
|
2022-12-06 03:08:20 -03:00
|
|
|
ErrorOr<void> create_layout_tree(DOM::Node&, Context&);
|
2020-11-26 21:18:34 +01:00
|
|
|
|
2022-04-13 18:44:14 +02:00
|
|
|
void push_parent(Layout::NodeWithStyle& node) { m_ancestor_stack.append(node); }
|
|
|
|
void pop_parent() { m_ancestor_stack.take_last(); }
|
2020-11-26 21:18:34 +01:00
|
|
|
|
2023-09-04 17:39:15 +01:00
|
|
|
template<CSS::DisplayInternal, typename Callback>
|
2021-10-06 17:57:44 +02:00
|
|
|
void for_each_in_tree_with_internal_display(NodeWithStyle& root, Callback);
|
|
|
|
|
2023-09-04 17:39:15 +01:00
|
|
|
template<CSS::DisplayInside, typename Callback>
|
2021-10-06 17:57:44 +02:00
|
|
|
void for_each_in_tree_with_inside_display(NodeWithStyle& root, Callback);
|
2021-01-07 18:00:51 +01:00
|
|
|
|
|
|
|
void fixup_tables(NodeWithStyle& root);
|
|
|
|
void remove_irrelevant_boxes(NodeWithStyle& root);
|
|
|
|
void generate_missing_child_wrappers(NodeWithStyle& root);
|
2023-08-05 05:50:07 +00:00
|
|
|
Vector<JS::Handle<Box>> generate_missing_parents(NodeWithStyle& root);
|
|
|
|
void missing_cells_fixup(Vector<JS::Handle<Box>> const&);
|
2021-01-07 18:00:51 +01:00
|
|
|
|
2022-10-06 13:10:03 +02:00
|
|
|
enum class AppendOrPrepend {
|
|
|
|
Append,
|
|
|
|
Prepend,
|
|
|
|
};
|
2022-10-06 14:14:16 +02:00
|
|
|
void insert_node_into_inline_or_block_ancestor(Layout::Node&, CSS::Display, AppendOrPrepend);
|
2022-12-06 03:08:20 -03:00
|
|
|
ErrorOr<void> create_pseudo_element_if_needed(DOM::Element&, CSS::Selector::PseudoElement, AppendOrPrepend);
|
2022-10-06 13:10:03 +02:00
|
|
|
|
2022-10-17 14:41:50 +02:00
|
|
|
JS::GCPtr<Layout::Node> m_layout_root;
|
2023-02-26 16:09:02 -07:00
|
|
|
Vector<JS::NonnullGCPtr<Layout::NodeWithStyle>> m_ancestor_stack;
|
2019-10-15 12:22:41 +02:00
|
|
|
};
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
|
|
}
|