Truly independent web browser
LibWeb+WebContent: Hold window sizes while a rendering update flies
Andreas Klingabc978018252
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cppindex ed3c87dcd88..147d06c328a 100644--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp@@ -1538,6 +1538,15 @@ Layout::RustFFI::FfiFlightBlocker EventLoop::style_flight_blocker(DOM::Document&return Blocker::None;}+// The sizes the windows took as the update flew become the sizes of their traversables now that it ended.+static void take_viewport_sizes_held_for_rendering_update_in_flight()+{+ for (auto const& page : pages_of_local_roots()) {+ if (page->has_local_traversable())+ page->local_traversable()->take_viewport_size_held_for_rendering_update_in_flight();+ }+}+void EventLoop::resume_rendering_update_in_flight(){auto update = m_rendering_update_in_flight.release_nonnull();@@ -1553,6 +1562,7 @@ void EventLoop::resume_rendering_update_in_flight()for (auto const& page : pages_of_local_roots())page->client().did_finish_rendering_update();}+ take_viewport_sizes_held_for_rendering_update_in_flight();}// The rest of the last rendering update, which ended as its style update flew, runs before anything of the next@@ -1581,6 +1591,7 @@ bool EventLoop::finish_ended_rendering_update_as_its_layout_flew()update_the_rendering_after_style_and_layout(update->docs, update->frame_timestamp, update->serial, TakenLayout::AsItFlew, update.ptr());}update_whether_font_face_sets_are_pending_on_the_environment(update->docs, TakenLayout::AsItFlew);+ take_viewport_sizes_held_for_rendering_update_in_flight();return true;}diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 8505292a156..469c9ee0726 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -4872,8 +4872,27 @@ Optional<CSSPixelPoint> LocalNavigable::to_local_root_viewport_position(CSSPixelreturn position;}+void LocalNavigable::set_viewport_size_after_rendering_update_in_flight(CSSPixelSize size)+{+ if (!HTML::main_thread_event_loop().has_rendering_update_in_flight()) {+ set_viewport_size(size);+ return;+ }+ // NB: Only the newest size counts. The sizes between are never shown.+ m_viewport_size_held_for_rendering_update_in_flight = size;+}++void LocalNavigable::take_viewport_size_held_for_rendering_update_in_flight()+{+ if (auto size = m_viewport_size_held_for_rendering_update_in_flight; size.has_value())+ set_viewport_size(*size);+}+void LocalNavigable::set_viewport_size(CSSPixelSize size, InvalidateDisplayList invalidate_display_list){+ // NB: A size set now is newer than any held one.+ m_viewport_size_held_for_rendering_update_in_flight.clear();+if (m_viewport_size == size && invalidate_display_list == InvalidateDisplayList::No)return;diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.hindex fd00a001e09..0d10cef698f 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.h+++ b/Libraries/LibWeb/HTML/LocalNavigable.h@@ -248,6 +248,11 @@ public:CSSPixelSize viewport_size() const { return m_viewport_size; }void set_viewport_size(CSSPixelSize, InvalidateDisplayList = InvalidateDisplayList::No);+ // A size the window takes as a rendering update is in flight waits for that update to end: the update flies for+ // the size it began with, and a new size would make the main thread wait for the flight and lay out again.+ void set_viewport_size_after_rendering_update_in_flight(CSSPixelSize);+ void take_viewport_size_held_for_rendering_update_in_flight();+// The part of the viewport of a local root another process embeds that the top-level viewport shows, in this// viewport's coordinates, as its embedder last reported. None of it until then.Optional<CSSPixelRect> viewport_intersection() const;@@ -644,6 +649,7 @@ private:ReplicatedContainerState m_root_container_state;CSSPixelSize m_viewport_size;+ Optional<CSSPixelSize> m_viewport_size_held_for_rendering_update_in_flight;Optional<CSSPixelRect> m_viewport_intersection;CSSPixelPoint m_viewport_scroll_offset;struct PendingPersistedStateRestoration {diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cppindex fd1c3555edd..6435b6a9e07 100644--- a/Services/WebContent/ConnectionFromClient.cpp+++ b/Services/WebContent/ConnectionFromClient.cpp@@ -408,6 +408,16 @@ void ConnectionFromClient::set_window_handle(Web::PageId page_id, String handle)}}+// A WebDriver command sees what the commands before it did, such as the viewport they set. The sizes that the windows+// took while a rendering update was in flight become their sizes before the command runs.+static void take_viewport_sizes_held_for_webdriver_command(PageHost& page_host)+{+ page_host.for_each_page([](PageClient& page_client) {+ if (page_client.page().has_local_traversable())+ page_client.page().local_traversable()->take_viewport_size_held_for_rendering_update_in_flight();+ });+}+void ConnectionFromClient::run_webdriver_command(Web::PageId page_id, u64 command_id, Optional<Web::HTML::CrossProcessId> navigable_id, String name, JsonValue payload, Vector<String> arguments){auto page = this->page(page_id);@@ -417,6 +427,7 @@ void ConnectionFromClient::run_webdriver_command(Web::PageId page_id, u64 commanreturn;}+ take_viewport_sizes_held_for_webdriver_command(*m_page_host);page->run_webdriver_command(command_id, navigable_id, name, move(payload), move(arguments));}@@ -429,6 +440,7 @@ void ConnectionFromClient::run_webdriver_bidi_command(Web::PageId page_id, u64 creturn;}+ take_viewport_sizes_held_for_webdriver_command(*m_page_host);WebContent::run_webdriver_bidi_command(*page, command_id, navigable_id, method, move(params));}diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cppindex 8fdd591c096..6736613d818 100644--- a/Services/WebContent/PageClient.cpp+++ b/Services/WebContent/PageClient.cpp@@ -630,8 +630,12 @@ void PageClient::set_viewport(Web::DevicePixelSize const& size, double device_pi// A viewport can arrive after the tab's document moved to another process, which leaves this page's traversable// remote. The page takes the viewport again once it displays the tab anew.- if (page().has_local_traversable())- page().local_traversable()->set_viewport_size(page().device_to_css_size(size), invalidate);+ if (page().has_local_traversable()) {+ if (invalidate == Web::InvalidateDisplayList::No)+ page().local_traversable()->set_viewport_size_after_rendering_update_in_flight(page().device_to_css_size(size));+ else+ page().local_traversable()->set_viewport_size(page().device_to_css_size(size), invalidate);+ }if (invalidate == Web::InvalidateDisplayList::PaintCommandsAndHitTestList)device_pixels_per_css_pixel_did_change();hurry_outstanding_rendering_opportunity();