From 62615dfc31f22d311f33ce7061436246ce5deca3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 14 Jun 2020 16:45:45 +0200 Subject: 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. --- Libraries/LibWeb/Layout/LayoutBox.cpp | 5 +---- Libraries/LibWeb/Layout/LayoutDocument.cpp | 3 +-- Libraries/LibWeb/Layout/LayoutNode.cpp | 17 +++++++++++++---- Libraries/LibWeb/Layout/LayoutNode.h | 3 +++ Libraries/LibWeb/Layout/LayoutWidget.cpp | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Libraries/LibWeb/Layout/LayoutBox.cpp b/Libraries/LibWeb/Layout/LayoutBox.cpp index 2f642b437b..3d79cc6f0c 100644 --- a/Libraries/LibWeb/Layout/LayoutBox.cpp +++ b/Libraries/LibWeb/Layout/LayoutBox.cpp @@ -260,11 +260,8 @@ HitTestResult LayoutBox::hit_test(const Gfx::IntPoint& position) const void LayoutBox::set_needs_display() { - auto* frame = document().frame(); - ASSERT(frame); - if (!is_inline()) { - const_cast(frame)->set_needs_display(enclosing_int_rect(absolute_rect())); + frame().set_needs_display(enclosing_int_rect(absolute_rect())); return; } diff --git a/Libraries/LibWeb/Layout/LayoutDocument.cpp b/Libraries/LibWeb/Layout/LayoutDocument.cpp index 5b42311047..75c5eace8e 100644 --- a/Libraries/LibWeb/Layout/LayoutDocument.cpp +++ b/Libraries/LibWeb/Layout/LayoutDocument.cpp @@ -43,8 +43,7 @@ LayoutDocument::~LayoutDocument() void LayoutDocument::layout(LayoutMode layout_mode) { - ASSERT(document().frame()); - set_width(document().frame()->size().width()); + set_width(frame().size().width()); LayoutNode::layout(layout_mode); diff --git a/Libraries/LibWeb/Layout/LayoutNode.cpp b/Libraries/LibWeb/Layout/LayoutNode.cpp index 95c0ef3105..1c8a43d718 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.cpp +++ b/Libraries/LibWeb/Layout/LayoutNode.cpp @@ -111,6 +111,18 @@ HitTestResult LayoutNode::hit_test(const Gfx::IntPoint& position) const 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 { if (is_anonymous()) @@ -151,13 +163,10 @@ void LayoutNode::split_into_lines(LayoutBlock& container, LayoutMode layout_mode void LayoutNode::set_needs_display() { - auto* frame = document().frame(); - ASSERT(frame); - if (auto* block = containing_block()) { block->for_each_fragment([&](auto& fragment) { if (&fragment.layout_node() == this || is_ancestor_of(fragment.layout_node())) { - const_cast(frame)->set_needs_display(enclosing_int_rect(fragment.absolute_rect())); + frame().set_needs_display(enclosing_int_rect(fragment.absolute_rect())); } return IterationDecision::Continue; }); diff --git a/Libraries/LibWeb/Layout/LayoutNode.h b/Libraries/LibWeb/Layout/LayoutNode.h index 4fb6b03076..c2ad503bdd 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.h +++ b/Libraries/LibWeb/Layout/LayoutNode.h @@ -103,6 +103,9 @@ public: Document& document(); const Document& document() const; + const Frame& frame() const; + Frame& frame(); + const LayoutDocument& root() const; LayoutDocument& root(); diff --git a/Libraries/LibWeb/Layout/LayoutWidget.cpp b/Libraries/LibWeb/Layout/LayoutWidget.cpp index e6cda54b32..4ddb86f3ac 100644 --- a/Libraries/LibWeb/Layout/LayoutWidget.cpp +++ b/Libraries/LibWeb/Layout/LayoutWidget.cpp @@ -60,7 +60,7 @@ void LayoutWidget::did_set_rect() void LayoutWidget::update_widget() { auto adjusted_widget_position = absolute_rect().location().to_int_point(); - auto& page_view = static_cast(document().frame()->page().client()); + auto& page_view = static_cast(frame().page().client()); adjusted_widget_position.move_by(-page_view.horizontal_scrollbar().value(), -page_view.vertical_scrollbar().value()); widget().move_to(adjusted_widget_position); } -- cgit v1.2.3