1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 19:17:41 +00:00

LibWeb: Add LayoutNode::frame() reference getter

Any live layout tree always has a corresponding live Frame, as we will
never create a layout tree for a frameless document.
This commit is contained in:
Andreas Kling 2020-06-14 16:45:45 +02:00
parent a93fb7299f
commit 62615dfc31
5 changed files with 19 additions and 11 deletions

View file

@ -260,11 +260,8 @@ HitTestResult LayoutBox::hit_test(const Gfx::IntPoint& position) const
void LayoutBox::set_needs_display() void LayoutBox::set_needs_display()
{ {
auto* frame = document().frame();
ASSERT(frame);
if (!is_inline()) { if (!is_inline()) {
const_cast<Frame*>(frame)->set_needs_display(enclosing_int_rect(absolute_rect())); frame().set_needs_display(enclosing_int_rect(absolute_rect()));
return; return;
} }

View file

@ -43,8 +43,7 @@ LayoutDocument::~LayoutDocument()
void LayoutDocument::layout(LayoutMode layout_mode) void LayoutDocument::layout(LayoutMode layout_mode)
{ {
ASSERT(document().frame()); set_width(frame().size().width());
set_width(document().frame()->size().width());
LayoutNode::layout(layout_mode); LayoutNode::layout(layout_mode);

View file

@ -111,6 +111,18 @@ HitTestResult LayoutNode::hit_test(const Gfx::IntPoint& position) const
return result; return result;
} }
const Frame& LayoutNode::frame() const
{
ASSERT(document().frame());
return *document().frame();
}
Frame& LayoutNode::frame()
{
ASSERT(document().frame());
return *document().frame();
}
const Document& LayoutNode::document() const const Document& LayoutNode::document() const
{ {
if (is_anonymous()) if (is_anonymous())
@ -151,13 +163,10 @@ void LayoutNode::split_into_lines(LayoutBlock& container, LayoutMode layout_mode
void LayoutNode::set_needs_display() void LayoutNode::set_needs_display()
{ {
auto* frame = document().frame();
ASSERT(frame);
if (auto* block = containing_block()) { if (auto* block = containing_block()) {
block->for_each_fragment([&](auto& fragment) { block->for_each_fragment([&](auto& fragment) {
if (&fragment.layout_node() == this || is_ancestor_of(fragment.layout_node())) { if (&fragment.layout_node() == this || is_ancestor_of(fragment.layout_node())) {
const_cast<Frame*>(frame)->set_needs_display(enclosing_int_rect(fragment.absolute_rect())); frame().set_needs_display(enclosing_int_rect(fragment.absolute_rect()));
} }
return IterationDecision::Continue; return IterationDecision::Continue;
}); });

View file

@ -103,6 +103,9 @@ public:
Document& document(); Document& document();
const Document& document() const; const Document& document() const;
const Frame& frame() const;
Frame& frame();
const LayoutDocument& root() const; const LayoutDocument& root() const;
LayoutDocument& root(); LayoutDocument& root();

View file

@ -60,7 +60,7 @@ void LayoutWidget::did_set_rect()
void LayoutWidget::update_widget() void LayoutWidget::update_widget()
{ {
auto adjusted_widget_position = absolute_rect().location().to_int_point(); auto adjusted_widget_position = absolute_rect().location().to_int_point();
auto& page_view = static_cast<const PageView&>(document().frame()->page().client()); auto& page_view = static_cast<const PageView&>(frame().page().client());
adjusted_widget_position.move_by(-page_view.horizontal_scrollbar().value(), -page_view.vertical_scrollbar().value()); adjusted_widget_position.move_by(-page_view.horizontal_scrollbar().value(), -page_view.vertical_scrollbar().value());
widget().move_to(adjusted_widget_position); widget().move_to(adjusted_widget_position);
} }