1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:17:45 +00:00

LibWeb: Add Page abstraction between PageView and main Frame

* A PageView is a view onto a Page object.
* A Page always has a main Frame (root of Frame tree.)
* Page has a PageClient. PageView is a PageClient.

The goal here is to allow building another kind of view onto
a Page while keeping the rest of LibWeb intact.
This commit is contained in:
Andreas Kling 2020-06-08 20:31:49 +02:00
parent 5072d4e02d
commit 92392398a2
16 changed files with 351 additions and 179 deletions

View file

@ -29,11 +29,13 @@
#include <AK/URL.h>
#include <LibGUI/ScrollableWidget.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Page.h>
namespace Web {
class PageView : public GUI::ScrollableWidget {
class PageView final
: public GUI::ScrollableWidget
, public PageClient {
C_OBJECT(PageView);
public:
@ -52,9 +54,6 @@ public:
const LayoutDocument* layout_root() const;
LayoutDocument* layout_root();
Web::Frame& main_frame() { return *m_main_frame; }
const Web::Frame& main_frame() const { return *m_main_frame; }
void reload();
bool load(const URL&);
void scroll_to_anchor(const StringView&);
@ -75,17 +74,12 @@ public:
virtual bool accepts_focus() const override { return true; }
void notify_link_click(Badge<EventHandler>, Web::Frame&, const String& href, const String& target, unsigned modifiers);
void notify_link_middle_click(Badge<EventHandler>, Web::Frame&, const String& href, const String& target, unsigned modifiers);
void notify_link_context_menu_request(Badge<EventHandler>, Web::Frame&, const Gfx::Point& content_position, const String& href, const String& target, unsigned modifiers);
void notify_link_hover(Badge<EventHandler>, Web::Frame&, const String& href);
void notify_tooltip_area_enter(Badge<EventHandler>, Web::Frame&, const Gfx::Point& content_position, const String& title);
void notify_tooltip_area_leave(Badge<EventHandler>, Web::Frame&);
void notify_needs_display(Badge<Web::Frame>, Web::Frame&, const Gfx::Rect&);
protected:
private:
PageView();
Page& page() { return *m_page; }
const Page& page() const { return *m_page; }
virtual void resize_event(GUI::ResizeEvent&) override;
virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
@ -94,17 +88,29 @@ protected:
virtual void keydown_event(GUI::KeyEvent&) override;
virtual void drop_event(GUI::DropEvent&) override;
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;
// ^Web::PageClient
virtual void page_did_change_title(const String&) override;
virtual void page_did_set_document_in_main_frame(Document*) override;
virtual void page_did_start_loading(const URL&) override;
virtual void page_did_change_selection() override;
virtual void page_did_request_cursor_change(GUI::StandardCursor) override;
virtual void page_did_request_link_context_menu(const Gfx::Point&, const String& href, const String& target, unsigned modifiers) override;
virtual void page_did_click_link(const String& href, const String& target, unsigned modifiers) override;
virtual void page_did_middle_click_link(const String& href, const String& target, unsigned modifiers) override;
virtual void page_did_enter_tooltip_area(const Gfx::Point&, const String&) override;
virtual void page_did_leave_tooltip_area() override;
virtual void page_did_hover_link(const URL&) override;
virtual void page_did_unhover_link() override;
virtual void page_did_request_scroll_to_anchor(const String& fragment) override;
virtual void page_did_invalidate(const Gfx::Rect&) override;
void layout_and_sync_size();
RefPtr<Web::Frame> m_main_frame;
bool m_should_show_line_box_borders { false };
NonnullOwnPtr<Page> m_page;
};
}