1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 15:47:34 +00:00

LibWeb+WebContent: Keep track of screen rect

It is now possible to get the up-to-date screen rect from a Web::Page.
This commit is contained in:
Linus Groh 2021-04-04 00:12:37 +02:00 committed by Andreas Kling
parent 96b26ec125
commit e8739ddab7
9 changed files with 29 additions and 1 deletions

View file

@ -27,6 +27,7 @@
#pragma once
#include <AK/URL.h>
#include <LibGUI/Desktop.h>
#include <LibGUI/ScrollableWidget.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Page/Page.h>
@ -85,8 +86,9 @@ private:
virtual void did_scroll() override;
// ^Web::PageClient
virtual Gfx::Palette palette() const override { return GUI::ScrollableWidget::palette(); }
virtual bool is_multi_process() const override { return false; }
virtual Gfx::Palette palette() const override { return GUI::ScrollableWidget::palette(); }
virtual Gfx::IntRect screen_rect() const override { return GUI::Desktop::the().rect(); }
virtual void page_did_change_title(const String&) override;
virtual void page_did_set_document_in_main_frame(DOM::Document*) override;
virtual void page_did_start_loading(const URL&) override;

View file

@ -29,6 +29,7 @@
#include <AK/String.h>
#include <AK/URLParser.h>
#include <LibGUI/Application.h>
#include <LibGUI/Desktop.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h>
@ -88,6 +89,7 @@ void OutOfProcessWebView::create_client()
};
client().post_message(Messages::WebContentServer::UpdateSystemTheme(Gfx::current_system_theme_buffer()));
client().post_message(Messages::WebContentServer::UpdateScreenRect(GUI::Desktop::the().rect()));
}
void OutOfProcessWebView::load(const URL& url)
@ -208,6 +210,11 @@ void OutOfProcessWebView::theme_change_event(GUI::ThemeChangeEvent& event)
request_repaint();
}
void OutOfProcessWebView::screen_rect_change_event(GUI::ScreenRectChangeEvent& event)
{
client().post_message(Messages::WebContentServer::UpdateScreenRect(event.rect()));
}
void OutOfProcessWebView::notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id)
{
if (m_client_state.back_bitmap_id == bitmap_id) {

View file

@ -91,6 +91,7 @@ private:
virtual void mousewheel_event(GUI::MouseEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override;
virtual void theme_change_event(GUI::ThemeChangeEvent&) override;
virtual void screen_rect_change_event(GUI::ScreenRectChangeEvent&) override;
// ^ScrollableWidget
virtual void did_scroll() override;

View file

@ -72,6 +72,11 @@ Gfx::Palette Page::palette() const
return m_client.palette();
}
Gfx::IntRect Page::screen_rect() const
{
return m_client.screen_rect();
}
bool Page::handle_mousewheel(const Gfx::IntPoint& position, unsigned button, unsigned modifiers, int wheel_delta)
{
return main_frame().event_handler().handle_mousewheel(position, button, modifiers, wheel_delta);

View file

@ -74,6 +74,7 @@ public:
bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
Gfx::Palette palette() const;
Gfx::IntRect screen_rect() const;
private:
PageClient& m_client;
@ -86,6 +87,7 @@ class PageClient {
public:
virtual bool is_multi_process() const = 0;
virtual Gfx::Palette palette() const = 0;
virtual Gfx::IntRect screen_rect() const = 0;
virtual void page_did_set_document_in_main_frame(DOM::Document*) { }
virtual void page_did_change_title(const String&) { }
virtual void page_did_start_loading(const URL&) { }