Skip to content

Commit dfc7534

Browse files
shannonboothADKaster
authored andcommitted
Ladybird/Qt: Factor out a method to update the screen rects
1 parent 97bf9e7 commit dfc7534

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

Ladybird/Qt/WebContentView.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,26 @@ void WebContentView::update_palette(PaletteMode mode)
528528
client().async_update_system_theme(m_client_state.page_index, make_system_theme_from_qt_palette(*this, mode));
529529
}
530530

531+
void WebContentView::update_screen_rects()
532+
{
533+
auto screens = QGuiApplication::screens();
534+
535+
if (!screens.empty()) {
536+
Vector<Web::DevicePixelRect> screen_rects;
537+
for (auto const& screen : screens) {
538+
auto geometry = screen->geometry();
539+
screen_rects.append(Web::DevicePixelRect(geometry.x(), geometry.y(), geometry.width(), geometry.height()));
540+
}
541+
542+
// FIXME: Update the screens again when QGuiApplication::screenAdded/Removed signals are emitted
543+
544+
// NOTE: The first item in QGuiApplication::screens is always the primary screen.
545+
// This is not specified in the documentation but QGuiApplication::primaryScreen
546+
// always returns the first item in the list if it isn't empty.
547+
client().async_update_screen_rects(m_client_state.page_index, screen_rects, 0);
548+
}
549+
}
550+
531551
void WebContentView::initialize_client(WebView::ViewImplementation::CreateNewClient create_new_client)
532552
{
533553
if (create_new_client == CreateNewClient::Yes) {
@@ -563,25 +583,7 @@ void WebContentView::initialize_client(WebView::ViewImplementation::CreateNewCli
563583
update_palette();
564584
client().async_update_system_fonts(m_client_state.page_index, Gfx::FontDatabase::default_font_query(), Gfx::FontDatabase::fixed_width_font_query(), Gfx::FontDatabase::window_title_font_query());
565585

566-
auto screens = QGuiApplication::screens();
567-
568-
if (!screens.empty()) {
569-
Vector<Web::DevicePixelRect> screen_rects;
570-
for (auto const& screen : screens) {
571-
// NOTE: QScreen::geometry() returns the 'device-independent pixels', we multiply
572-
// by the device pixel ratio to get the 'physical pixels' of the display.
573-
auto geometry = screen->geometry();
574-
auto device_pixel_ratio = screen->devicePixelRatio();
575-
screen_rects.append(Web::DevicePixelRect(geometry.x(), geometry.y(), geometry.width() * device_pixel_ratio, geometry.height() * device_pixel_ratio));
576-
}
577-
578-
// FIXME: Update the screens again when QGuiApplication::screenAdded/Removed signals are emitted
579-
580-
// NOTE: The first item in QGuiApplication::screens is always the primary screen.
581-
// This is not specified in the documentation but QGuiApplication::primaryScreen
582-
// always returns the first item in the list if it isn't empty.
583-
client().async_update_screen_rects(m_client_state.page_index, screen_rects, 0);
584-
}
586+
update_screen_rects();
585587

586588
if (!m_webdriver_content_ipc_path.is_empty())
587589
client().async_connect_to_webdriver(m_client_state.page_index, m_webdriver_content_ipc_path);

Ladybird/Qt/WebContentView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class WebContentView final
100100
void enqueue_native_event(Web::MouseEvent::Type, QSinglePointEvent const& event);
101101
void enqueue_native_event(Web::KeyEvent::Type, QKeyEvent const& event);
102102
void finish_handling_key_event(Web::KeyEvent const&);
103+
void update_screen_rects();
103104

104105
bool m_should_show_line_box_borders { false };
105106

0 commit comments

Comments
 (0)