diff --git a/Libraries/LibWeb/DOM/HTMLIFrameElement.cpp b/Libraries/LibWeb/DOM/HTMLIFrameElement.cpp
index 8f48779c57..10b23822c5 100644
--- a/Libraries/LibWeb/DOM/HTMLIFrameElement.cpp
+++ b/Libraries/LibWeb/DOM/HTMLIFrameElement.cpp
@@ -79,11 +79,6 @@ void HTMLIFrameElement::load_src(const String& value)
return;
}
- m_hosted_frame->on_set_needs_display = [this](auto&) {
- if (layout_node())
- layout_node()->set_needs_display();
- };
-
m_hosted_frame->loader().load(url);
}
diff --git a/Libraries/LibWeb/Frame/Frame.cpp b/Libraries/LibWeb/Frame/Frame.cpp
index ec73c37854..dbebd6f6c3 100644
--- a/Libraries/LibWeb/Frame/Frame.cpp
+++ b/Libraries/LibWeb/Frame/Frame.cpp
@@ -93,9 +93,14 @@ void Frame::set_needs_display(const Gfx::Rect& rect)
if (!m_viewport_rect.intersects(rect))
return;
- if (!on_set_needs_display)
+ if (is_main_frame()) {
+ if (page_view())
+ page_view()->notify_needs_display({}, *this, rect);
return;
- on_set_needs_display(rect);
+ }
+
+ if (host_element() && host_element()->layout_node())
+ host_element()->layout_node()->set_needs_display();
}
void Frame::did_scroll(Badge)
diff --git a/Libraries/LibWeb/Frame/Frame.h b/Libraries/LibWeb/Frame/Frame.h
index 90ed25fb5a..57458cc575 100644
--- a/Libraries/LibWeb/Frame/Frame.h
+++ b/Libraries/LibWeb/Frame/Frame.h
@@ -60,7 +60,6 @@ public:
void set_needs_display(const Gfx::Rect&);
- Function on_set_needs_display;
Function on_title_change;
Function on_load_start;
Function on_favicon_change;
diff --git a/Libraries/LibWeb/PageView.cpp b/Libraries/LibWeb/PageView.cpp
index 4ed333bf01..f26332d1c6 100644
--- a/Libraries/LibWeb/PageView.cpp
+++ b/Libraries/LibWeb/PageView.cpp
@@ -72,15 +72,6 @@ PageView::PageView()
if (on_load_start)
on_load_start(url);
};
- main_frame().on_set_needs_display = [this](auto& content_rect) {
- if (content_rect.is_empty()) {
- update();
- return;
- }
- Gfx::Rect adjusted_rect = content_rect;
- adjusted_rect.set_location(to_widget_position(content_rect.location()));
- update(adjusted_rect);
- };
set_should_hide_unnecessary_scrollbars(true);
set_background_role(ColorRole::Base);
@@ -334,6 +325,22 @@ Gfx::Point PageView::to_screen_position(const Web::Frame& frame, const Gfx::Poin
return screen_relative_rect().location().translated(offset).translated(frame_position);
}
+Gfx::Rect PageView::to_widget_rect(const Web::Frame& frame, const Gfx::Rect& frame_rect) const
+{
+ Gfx::Point offset;
+ for (auto* f = &frame; f; f = f->parent()) {
+ if (!f->host_element())
+ return {};
+ if (!f->host_element()->layout_node())
+ return {};
+ auto f_position = f->host_element()->layout_node()->box_type_agnostic_position().to_int_point();
+ offset.move_by(f_position);
+ }
+
+ auto content_position = frame_rect.location().translated(offset);
+ return { to_widget_position(content_position), frame_rect.size() };
+}
+
void PageView::notify_link_context_menu_request(Badge, Web::Frame& frame, const Gfx::Point& content_position, const String& href, const String&, unsigned)
{
if (on_link_context_menu_request)
@@ -356,4 +363,9 @@ void PageView::notify_tooltip_area_leave(Badge, Web::Frame&)
GUI::Application::the().hide_tooltip();
}
+void PageView::notify_needs_display(Badge, Web::Frame& frame, const Gfx::Rect& rect)
+{
+ update(to_widget_rect(frame, rect));
+}
+
}
diff --git a/Libraries/LibWeb/PageView.h b/Libraries/LibWeb/PageView.h
index 0bd808c988..f91f097044 100644
--- a/Libraries/LibWeb/PageView.h
+++ b/Libraries/LibWeb/PageView.h
@@ -81,6 +81,7 @@ public:
void notify_link_hover(Badge, Web::Frame&, const String& href);
void notify_tooltip_area_enter(Badge, Web::Frame&, const Gfx::Point& content_position, const String& title);
void notify_tooltip_area_leave(Badge, Web::Frame&);
+ void notify_needs_display(Badge, Web::Frame&, const Gfx::Rect&);
protected:
PageView();
@@ -97,6 +98,7 @@ private:
virtual void did_scroll() override;
Gfx::Point to_screen_position(const Web::Frame&, const Gfx::Point&) const;
+ Gfx::Rect to_widget_rect(const Web::Frame&, const Gfx::Rect&) const;
void layout_and_sync_size();