headless-browser: Update the viewport when WebDriver resizes the window

When the window resizes, we should also update the viewport to match,
rather than remaining at the hard-coded 800x600 size.
This commit is contained in:
Timothy Flynn 2024-11-12 11:02:06 -05:00 committed by Andreas Kling
parent 71ccaeda16
commit e094712e3a
Notes: github-actions[bot] 2024-11-13 10:02:07 +00:00

View file

@ -45,21 +45,30 @@ HeadlessWebView::HeadlessWebView(Core::AnonymousBuffer theme, Web::DevicePixelSi
}; };
on_resize_window = [this](auto size) { on_resize_window = [this](auto size) {
client().async_set_window_size(m_client_state.page_index, size.template to_type<Web::DevicePixels>()); m_viewport_size = size.template to_type<Web::DevicePixels>();
client().async_set_window_size(m_client_state.page_index, m_viewport_size);
client().async_set_viewport_size(m_client_state.page_index, m_viewport_size);
client().async_did_update_window_rect(m_client_state.page_index); client().async_did_update_window_rect(m_client_state.page_index);
}; };
on_maximize_window = [this]() { on_maximize_window = [this]() {
m_viewport_size = screen_rect.size();
client().async_set_window_position(m_client_state.page_index, screen_rect.location()); client().async_set_window_position(m_client_state.page_index, screen_rect.location());
client().async_set_window_size(m_client_state.page_index, screen_rect.size()); client().async_set_window_size(m_client_state.page_index, screen_rect.size());
client().async_set_viewport_size(m_client_state.page_index, screen_rect.size());
client().async_did_update_window_rect(m_client_state.page_index); client().async_did_update_window_rect(m_client_state.page_index);
}; };
on_fullscreen_window = [this]() { on_fullscreen_window = [this]() {
m_viewport_size = screen_rect.size();
client().async_set_window_position(m_client_state.page_index, screen_rect.location()); client().async_set_window_position(m_client_state.page_index, screen_rect.location());
client().async_set_window_size(m_client_state.page_index, screen_rect.size()); client().async_set_window_size(m_client_state.page_index, screen_rect.size());
client().async_set_viewport_size(m_client_state.page_index, screen_rect.size());
client().async_did_update_window_rect(m_client_state.page_index); client().async_did_update_window_rect(m_client_state.page_index);
}; };