Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Libraries/LibWeb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ set(SOURCES
Layout/ListItemMarkerBox.cpp
Layout/NavigableContainerViewport.cpp
Layout/Node.cpp
Layout/NodeArena.cpp
Layout/RadioButton.cpp
Layout/RangeInputBox.cpp
Layout/ReplacedBox.cpp
Expand Down
10 changes: 10 additions & 0 deletions Libraries/LibWeb/DOM/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/IntersectionObserver/IntersectionObserver.h>
#include <LibWeb/Layout/BlockFormattingContext.h>
#include <LibWeb/Layout/NodeArena.h>
#include <LibWeb/Layout/SVGFormattingContext.h>
#include <LibWeb/Layout/SVGSVGBox.h>
#include <LibWeb/Layout/ScrollableOverflow.h>
Expand Down Expand Up @@ -619,6 +620,15 @@ Document::Document(JS::Realm& realm, URL::URL const& url)

Document::~Document() = default;

Layout::NodeArena& Document::layout_node_arena()
{
// Created on first layout node so documents that never build a layout tree (e.g. temporary
// fragment-parsing documents) skip the Rust arena round-trip entirely.
if (!m_layout_node_arena)
m_layout_node_arena = make_ref_counted<Layout::NodeArena>();
return *m_layout_node_arena;
}

void Document::set_temporary_document_for_fragment_parsing(Badge<HTML::HTMLParser>)
{
// https://html.spec.whatwg.org/multipage/parsing.html#html-fragment-parsing-algorithm
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LibWeb/DOM/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ class WEB_API Document
// one at construction; a full layout pass renumbers the whole tree densely and resets the
// counter past the dense range.
[[nodiscard]] u32 allocate_layout_node_index() { return m_next_layout_node_index++; }
[[nodiscard]] Layout::NodeArena& layout_node_arena();
void reset_layout_node_index_counter(u32 next_index)
{
m_next_layout_node_index = next_index;
Expand Down Expand Up @@ -1422,6 +1423,7 @@ class WEB_API Document

GC::Ptr<HTML::Window> m_window;

RefPtr<Layout::NodeArena> m_layout_node_arena;
RefPtr<Layout::Viewport> m_layout_root;

GC::Ptr<Node> m_hovered_node;
Expand Down
1 change: 1 addition & 0 deletions Libraries/LibWeb/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ class LineBoxFragment;
class ListItemBox;
class ListItemMarkerBox;
class Node;
class NodeArena;
class NodeWithStyle;
class NodeWithStyleAndBoxModelMetrics;
class RadioButton;
Expand Down
3 changes: 1 addition & 2 deletions Libraries/LibWeb/Layout/AudioBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
namespace Web::Layout {

class AudioBox final : public ReplacedBox {
GC_CELL(AudioBox, ReplacedBox);
GC_DECLARE_ALLOCATOR(AudioBox);
LAYOUT_NODE(AudioBox, ReplacedBox);

public:
AudioBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::ComputedValues const>);
Expand Down
18 changes: 7 additions & 11 deletions Libraries/LibWeb/Layout/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ struct IntrinsicSizes {
};

class WEB_API Box : public NodeWithStyleAndBoxModelMetrics {
GC_CELL(Box, NodeWithStyleAndBoxModelMetrics);
GC_DECLARE_ALLOCATOR(Box);
LAYOUT_NODE(Box, NodeWithStyleAndBoxModelMetrics);

public:
RefPtr<Painting::Paintable const> paintable_box() const;
Expand Down Expand Up @@ -87,18 +86,18 @@ class WEB_API Box : public NodeWithStyleAndBoxModelMetrics {
// Whether an absolutely or fixed positioned descendant of this box has its containing
// block outside this box's subtree, so the descendant's layout escapes the subtree.
// Re-derived whenever containing block pointers are recomputed.
bool abspos_descendant_escapes() const { return m_abspos_descendant_escapes; }
void set_abspos_descendant_escapes(bool value) { m_abspos_descendant_escapes = value; }
bool abspos_descendant_escapes() const { return has_flag(RustFFI::NodeFlag::AbsposDescendantEscapes); }
void set_abspos_descendant_escapes(bool value) { set_flag(RustFFI::NodeFlag::AbsposDescendantEscapes, value); }

void set_default_scroll_shift(WeakPtr<Node> anchor, bool compensates_for_horizontal_scroll, bool compensates_for_vertical_scroll)
{
m_default_scroll_shift_anchor = move(anchor);
m_compensates_for_horizontal_scroll = compensates_for_horizontal_scroll;
m_compensates_for_vertical_scroll = compensates_for_vertical_scroll;
set_flag(RustFFI::NodeFlag::CompensatesForHorizontalScroll, compensates_for_horizontal_scroll);
set_flag(RustFFI::NodeFlag::CompensatesForVerticalScroll, compensates_for_vertical_scroll);
}
Node* default_scroll_shift_anchor() const { return m_default_scroll_shift_anchor.ptr(); }
bool compensates_for_horizontal_scroll() const { return m_compensates_for_horizontal_scroll; }
bool compensates_for_vertical_scroll() const { return m_compensates_for_vertical_scroll; }
bool compensates_for_horizontal_scroll() const { return has_flag(RustFFI::NodeFlag::CompensatesForHorizontalScroll); }
bool compensates_for_vertical_scroll() const { return has_flag(RustFFI::NodeFlag::CompensatesForVerticalScroll); }

IntrinsicSizes& cached_intrinsic_sizes() const
{
Expand All @@ -119,9 +118,6 @@ class WEB_API Box : public NodeWithStyleAndBoxModelMetrics {
OwnPtr<AbsposLayoutInputs> m_saved_abspos_layout_inputs;

WeakPtr<Node> m_default_scroll_shift_anchor;
bool m_compensates_for_horizontal_scroll { false };
bool m_compensates_for_vertical_scroll { false };
bool m_abspos_descendant_escapes { false };

OwnPtr<IntrinsicSizes> mutable m_cached_intrinsic_sizes;
};
Expand Down
Loading