Skip to content

Commit

Permalink
LibWeb: Store overflow data in the FormattingState
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Feb 21, 2022
1 parent 92266d2 commit 2615728
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
6 changes: 2 additions & 4 deletions Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m
auto viewport_rect = root().browsing_context().viewport_rect();

auto& icb = verify_cast<Layout::InitialContainingBlock>(root());
auto& icb_state = m_state.ensure(icb);

VERIFY(!icb.children_are_inline());
layout_block_level_children(root(), layout_mode);
Expand All @@ -546,13 +547,10 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m

if (bottom_edge >= viewport_rect.height() || right_edge >= viewport_rect.width()) {
// FIXME: Move overflow data to FormattingState!
auto& overflow_data = const_cast<InitialContainingBlock&>(icb).ensure_overflow_data();
auto& overflow_data = icb_state.ensure_overflow_data();
overflow_data.scrollable_overflow_rect = viewport_rect.to_type<float>();
// NOTE: The edges are *within* the rectangle, so we add 1 to get the width and height.
overflow_data.scrollable_overflow_rect.set_size(right_edge + 1, bottom_edge + 1);
} else {
// FIXME: Move overflow data to FormattingState!
const_cast<InitialContainingBlock&>(icb).clear_overflow_data();
}
}

Expand Down
9 changes: 1 addition & 8 deletions Userland/Libraries/LibWeb/Layout/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,7 @@ class Box : public NodeWithStyleAndBoxModelMetrics {
return m_overflow_data->scrollable_overflow_rect;
}

OverflowData& ensure_overflow_data()
{
if (!m_overflow_data)
m_overflow_data = make<OverflowData>();
return *m_overflow_data;
}

void clear_overflow_data() { m_overflow_data = nullptr; }
void set_overflow_data(OwnPtr<OverflowData> data) { m_overflow_data = move(data); }

virtual void before_children_paint(PaintContext&, PaintPhase) override;
virtual void after_children_paint(PaintContext&, PaintPhase) override;
Expand Down
3 changes: 2 additions & 1 deletion Userland/Libraries/LibWeb/Layout/FormattingState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ void FormattingState::commit()
node.box_model().border = { node_state.border_top, node_state.border_right, node_state.border_bottom, node_state.border_left };
node.box_model().margin = { node_state.margin_top, node_state.margin_right, node_state.margin_bottom, node_state.margin_left };

// For boxes, transfer relative offset and size.
// For boxes, transfer relative offset, size, and overflow data.
if (is<Layout::Box>(node)) {
auto& box = static_cast<Layout::Box&>(node);
box.set_offset(node_state.offset);
box.set_content_size(node_state.content_width, node_state.content_height);
box.set_overflow_data(move(node_state.overflow_data));
}

// For block containers, transfer line boxes.
Expand Down
11 changes: 10 additions & 1 deletion Userland/Libraries/LibWeb/Layout/FormattingState.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <AK/HashMap.h>
#include <LibGfx/Point.h>
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Layout/LineBox.h>
#include <LibWeb/Layout/Node.h>

namespace Web::Layout {

Expand Down Expand Up @@ -53,6 +53,15 @@ struct FormattingState {

float border_box_width() const { return border_box_left() + content_width + border_box_right(); }
float border_box_height() const { return border_box_top() + content_height + border_box_bottom(); }

OwnPtr<Layout::Box::OverflowData> overflow_data;

Layout::Box::OverflowData& ensure_overflow_data()
{
if (!overflow_data)
overflow_data = make<Layout::Box::OverflowData>();
return *overflow_data;
}
};

void commit();
Expand Down

0 comments on commit 2615728

Please sign in to comment.