LibHTML: Push the visible viewport rect from HtmlView to Frame

This will allow various mechanisms and optimizations based on the
currently visible viewport rect.
This commit is contained in:
Andreas Kling 2019-12-18 20:54:23 +01:00
parent 85ac9705ba
commit 7e068565bc
Notes: sideshowbarker 2024-07-19 10:49:02 +09:00
4 changed files with 20 additions and 0 deletions

View File

@ -32,6 +32,13 @@ void Frame::set_size(const Size& size)
m_size = size;
}
void Frame::set_viewport_rect(const Rect& rect)
{
if (m_viewport_rect == rect)
return;
m_viewport_rect = rect;
}
void Frame::set_needs_display(const Rect& rect)
{
if (!on_set_needs_display)

View File

@ -30,10 +30,14 @@ public:
void set_needs_display(const Rect&);
Function<void(const Rect&)> on_set_needs_display;
void set_viewport_rect(const Rect&);
Rect viewport_rect() const { return m_viewport_rect; }
private:
explicit Frame(HtmlView&);
WeakPtr<HtmlView> m_html_view;
RefPtr<Document> m_document;
Size m_size;
Rect m_viewport_rect;
};

View File

@ -95,6 +95,8 @@ void HtmlView::layout_and_sync_size()
set_content_size(enclosing_int_rect(layout_root()->rect()).size());
}
main_frame().set_viewport_rect(visible_content_rect());
#ifdef HTML_DEBUG
dbgprintf("\033[33;1mLayout tree after layout:\033[0m\n");
::dump_tree(*layout_root());
@ -381,3 +383,8 @@ void HtmlView::dump_selection(const char* event_name)
<< layout_root()->selection().start().layout_node << ":" << layout_root()->selection().start().index_in_node << ", end: "
<< layout_root()->selection().end().layout_node << ":" << layout_root()->selection().end().index_in_node;
}
void HtmlView::did_scroll()
{
main_frame().set_viewport_rect(visible_content_rect());
}

View File

@ -47,6 +47,8 @@ protected:
virtual void keydown_event(GKeyEvent&) override;
private:
virtual void did_scroll() override;
void layout_and_sync_size();
void dump_selection(const char* event_name);