Truly independent web browser
Compositor: Let ContextState reach the process through one host
Aliaksandr Kalenik5fa827ffcc77
diff --git a/Services/Compositor/CMakeLists.txt b/Services/Compositor/CMakeLists.txtindex 0bc48ab12c8..ad7db32ddac 100644--- a/Services/Compositor/CMakeLists.txt+++ b/Services/Compositor/CMakeLists.txt@@ -5,7 +5,6 @@ set(SOURCESBitmapExport.cppCanvas2DCommandPlayer.cppCanvasHost.cpp- CaretBlinkTimer.cppColorSpaceSkia.cppCompositorState.cppContextPresenter.cppdiff --git a/Services/Compositor/CaretBlinkTimer.cpp b/Services/Compositor/CaretBlinkTimer.cppdeleted file mode 100644index 5ab742aeb59..00000000000--- a/Services/Compositor/CaretBlinkTimer.cpp+++ /dev/null@@ -1,68 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <Compositor/CaretBlinkTimer.h>-#include <LibCompositing/DisplayList/DisplayList.h>-#include <LibCore/Timer.h>--namespace Compositor {--CaretBlinkTimer::CaretBlinkTimer(Function<Gfx::IntRect()> damage_rect_of_blinking_carets, Function<void(Gfx::IntRect)> schedule_repaint)- : m_damage_rect_of_blinking_carets(move(damage_rect_of_blinking_carets))- , m_schedule_repaint(move(schedule_repaint))-{-}--CaretBlinkTimer::~CaretBlinkTimer()-{- if (m_timer) {- m_timer->on_timeout = {};- m_timer->stop();- }-}--void CaretBlinkTimer::did_install_display_list(Compositing::DisplayList const& display_list)-{- Optional<i64> blink_cycle_start_time_ns;- display_list.for_each_caret([&](auto, auto, auto const& caret) {- if (caret.should_blink)- blink_cycle_start_time_ns = caret.blink_cycle_start_time_ns;- });-- if (blink_cycle_start_time_ns == m_blink_cycle_start_time_ns)- return;- m_blink_cycle_start_time_ns = blink_cycle_start_time_ns;-- if (m_timer)- m_timer->stop();- if (!m_blink_cycle_start_time_ns.has_value() || !m_schedule_repaint)- return;-- if (!m_timer) {- m_timer = Core::Timer::create_single_shot(AK::Duration::from_milliseconds(500), [this] {- auto damage_rect = m_damage_rect_of_blinking_carets();- if (!damage_rect.is_empty())- m_schedule_repaint(damage_rect);- schedule_next_blink();- });- }- schedule_next_blink();-}--void CaretBlinkTimer::schedule_next_blink()-{- if (!m_blink_cycle_start_time_ns.has_value() || !m_timer)- return;-- auto now_ns = MonotonicTime::now().nanoseconds();- auto elapsed_ns = now_ns > *m_blink_cycle_start_time_ns- ? now_ns - *m_blink_cycle_start_time_ns- : 0;- auto delay_ns = Compositing::caret_blink_interval_ns - elapsed_ns % Compositing::caret_blink_interval_ns;- m_timer->restart(AK::Duration::from_nanoseconds(delay_ns));-}--}diff --git a/Services/Compositor/CaretBlinkTimer.h b/Services/Compositor/CaretBlinkTimer.hdeleted file mode 100644index a5b0d7df3ad..00000000000--- a/Services/Compositor/CaretBlinkTimer.h+++ /dev/null@@ -1,39 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/Function.h>-#include <AK/Noncopyable.h>-#include <AK/Optional.h>-#include <AK/RefPtr.h>-#include <LibCompositing/Forward.h>-#include <LibCore/Forward.h>-#include <LibGfx/Rect.h>--namespace Compositor {--// Repaints the blinking caret of a display list each time its blink cycle turns it on or off.-class CaretBlinkTimer {- AK_MAKE_NONCOPYABLE(CaretBlinkTimer);- AK_MAKE_NONMOVABLE(CaretBlinkTimer);--public:- CaretBlinkTimer(Function<Gfx::IntRect()> damage_rect_of_blinking_carets, Function<void(Gfx::IntRect)> schedule_repaint);- ~CaretBlinkTimer();-- void did_install_display_list(Compositing::DisplayList const&);--private:- void schedule_next_blink();-- Function<Gfx::IntRect()> m_damage_rect_of_blinking_carets;- Function<void(Gfx::IntRect)> m_schedule_repaint;- RefPtr<Core::Timer> m_timer;- Optional<i64> m_blink_cycle_start_time_ns;-};--}diff --git a/Services/Compositor/CompositorCoreHost.h b/Services/Compositor/CompositorCoreHost.hnew file mode 100644index 00000000000..42e9cde8a42--- /dev/null+++ b/Services/Compositor/CompositorCoreHost.h@@ -0,0 +1,42 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/DistinctNumeric.h>+#include <AK/Time.h>+#include <LibIPC/Forward.h>+#include <LibWebCommon/Page/CompositorContextId.h>++namespace Compositor {++AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, WebContentClientId);++enum class ContextTimer : u8 {+ ScrollStepGestureInput,+ ScrollbarPaging,+ ScrollbarFadeOut,+ CaretBlink,+};++// What the scroll and input logic of the contexts asks of the process around it. None of these calls comes back into+// that logic before it returns.+class CompositorCoreHost {+public:+ virtual ~CompositorCoreHost() = default;++ // A message for a client that is gone is dropped.+ virtual void post_message_to_web_content(WebContentClientId, IPC::MessageBuffer&) = 0;+ // A client without a render clock channel hears nothing.+ virtual void post_message_to_render_clock_of_web_content(WebContentClientId, IPC::MessageBuffer&) = 0;+ // Display ticks reach a context whose scroll and input logic says it needs animation frames, while it is visible.+ virtual void request_display_ticks(Web::CompositorContextId) = 0;+ // Each timer of a context fires once after the delay, and setting it again replaces the delay.+ virtual void set_timer(Web::CompositorContextId, ContextTimer, AK::Duration delay) = 0;+ virtual void cancel_timer(Web::CompositorContextId, ContextTimer) = 0;+};++}diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 5133429ef05..875a0ac217b 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -37,6 +37,73 @@ CompositorState::~CompositorState()m_gpu_completion_timer->stop();}+WebContentClientId CompositorState::register_web_content_client(CompositorStateWebContentClient& client)+{+ WebContentClientId client_id { m_next_web_content_client_id++ };+ m_web_content_clients.set(client_id, &client);+ return client_id;+}++CompositorStateWebContentClient* CompositorState::web_content_client_if_present(WebContentClientId client_id) const+{+ return m_web_content_clients.get(client_id).value_or(nullptr);+}++CompositorStateWebContentClient& CompositorState::web_content_client_of(ContextState const& context)+{+ auto* client = web_content_client_if_present(context.web_content_client_id());+ VERIFY(client);+ return *client;+}++void CompositorState::post_message_to_web_content(WebContentClientId client_id, IPC::MessageBuffer& buffer)+{+ if (auto* client = web_content_client_if_present(client_id))+ client->post_message_to_web_content(buffer);+}++void CompositorState::post_message_to_render_clock_of_web_content(WebContentClientId client_id, IPC::MessageBuffer& buffer)+{+ if (auto* client = web_content_client_if_present(client_id))+ client->post_message_to_render_clock(buffer);+}++void CompositorState::request_display_ticks(Web::CompositorContextId context_id)+{+ if (auto* context = context_if_present(context_id); context && context_is_effectively_visible(*context))+ vsync_scheduler_for_display(display_id_for_context(*context)).schedule(display_refresh_rate_for_context(*context));+}++void CompositorState::set_timer(Web::CompositorContextId context_id, ContextTimer timer, AK::Duration delay)+{+ auto& context_timer = m_context_timers.ensure(context_id).ensure(timer, [&] {+ return Core::Timer::create_single_shot(delay, [this, context_id, timer] {+ context_timer_fired(context_id, timer);+ });+ });+ context_timer->restart(delay);+}++void CompositorState::cancel_timer(Web::CompositorContextId context_id, ContextTimer timer)+{+ auto timers = m_context_timers.find(context_id);+ if (timers == m_context_timers.end())+ return;+ if (auto context_timer = timers->value.get(timer); context_timer.has_value())+ (*context_timer)->stop();+}++void CompositorState::context_timer_fired(Web::CompositorContextId context_id, ContextTimer timer)+{+ auto* context = context_if_present(context_id);+ if (!context)+ return;+ auto now = MonotonicTime::now();+ auto caret_damage_rect = context->timer_fired(timer, now);+ if (caret_damage_rect.has_value())+ schedule_caret_repaint(context_id, *caret_damage_rect);+}+void CompositorState::register_presentation(CompositorStateClient& presentation, PresentationCapabilities capabilities){m_presentations.set(&presentation, capabilities);@@ -99,7 +166,7 @@ CompositorStateClient* CompositorState::presentation_for_context(Web::Compositorreturn m_context_presentations.get(context_id).value_or(nullptr);}-CompositorState::ContextOwnerCheckResult CompositorState::check_context_owner(Web::CompositorContextId context_id, CompositorStateWebContentClient& client)+CompositorState::ContextOwnerCheckResult CompositorState::check_context_owner(Web::CompositorContextId context_id, WebContentClientId client){auto* context = context_if_present(context_id);if (!context)@@ -114,7 +181,7 @@ void CompositorState::destroy_contexts_for_web_content_client(CompositorStateWeb{Vector<Web::CompositorContextId> context_ids;for (auto& context : m_contexts) {- if (context.value->is_owned_by(client))+ if (context.value->is_owned_by(client.web_content_client_id()))context_ids.append(context.key);}@@ -131,6 +198,7 @@ void CompositorState::destroy_contexts_for_web_content_client(CompositorStateWebm_canvas_surface_registry.remove_canvas_surface(canvas_id);return true;});+ m_web_content_clients.remove(client.web_content_client_id());}CompositorState::PlaceholderCanvasAllocation CompositorState::allocate_placeholder_canvas(CompositorStateWebContentClient& client)@@ -193,14 +261,7 @@ void CompositorState::create_context(Web::CompositorContextId context_id, OptionVERIFY(context_id == Web::compositor_context_id_for_page(*page_id));auto& context = *m_contexts.ensure(context_id, [&] {- auto schedule_caret_repaint = [this, context_id](Gfx::IntRect damage_rect) {- this->schedule_caret_repaint(context_id, damage_rect);- };- auto request_animation_frames = [this, context_id] {- if (auto* context = context_if_present(context_id))- schedule_animation_frames_if_needed(*context);- };- return make<ContextState>(context_id, page_id, web_content_client, OwnedCanvasSurfaces { m_canvas_surface_registry, web_content_client.canvas_surface_owner_id() }, move(schedule_caret_repaint), move(request_animation_frames));+ return make<ContextState>(context_id, page_id, web_content_client.web_content_client_id(), *this, OwnedCanvasSurfaces { m_canvas_surface_registry, web_content_client.canvas_surface_owner_id() });});resize_backing_stores_if_needed(context_id, context);}@@ -221,6 +282,13 @@ void CompositorState::destroy_context(Web::CompositorContextId context_id)possible_child_context.set_parent_context({});}m_context_presentations.remove(context_id);+ if (auto timers = m_context_timers.find(context_id); timers != m_context_timers.end()) {+ for (auto& [_, timer] : timers->value) {+ timer->on_timeout = {};+ timer->stop();+ }+ m_context_timers.remove(timers);+ }m_contexts.remove(context_id);update_scroll_capabilities();update_unpainted_video_update_scheduling();@@ -396,7 +464,7 @@ void CompositorState::on_video_sink_ready(CompositorStateWebContentClient& clienupdate_unpainted_video_update_scheduling();});for (auto& context_entry : m_contexts) {- if (&context_entry.value->web_content_client() == &client)+ if (context_entry.value->web_content_client_id() == client.web_content_client_id())resolve_video_sinks(*context_entry.value);}present_contexts_drawing_video_sink(client, handle);@@ -494,7 +562,7 @@ bool CompositorState::animated_image_is_drawn(CompositorStateWebContentClient* c{for (auto& context_entry : m_contexts) {auto& context = *context_entry.value;- if (&context.web_content_client() == client && context_is_effectively_visible(context) && context.presenter().resource_storage().has_image_frame(id))+ if (context.web_content_client_id() == client->web_content_client_id() && context_is_effectively_visible(context) && context.presenter().resource_storage().has_image_frame(id))return true;}return false;@@ -504,7 +572,7 @@ void CompositorState::show_animated_image_frame(CompositorStateWebContentClient*{for (auto& context_entry : m_contexts) {auto& context = *context_entry.value;- if (&context.web_content_client() != client || !context.presenter().resource_storage().has_image_frame(id))+ if (context.web_content_client_id() != client->web_content_client_id() || !context.presenter().resource_storage().has_image_frame(id))continue;context.presenter().resource_storage().replace_image_frame_pixels(id, frame);if (!context_is_effectively_visible(context))@@ -516,7 +584,7 @@ void CompositorState::show_animated_image_frame(CompositorStateWebContentClient*void CompositorState::show_animated_image_frames_in(ContextState& context){- auto images = m_animated_images.find(&context.web_content_client());+ auto images = m_animated_images.find(&web_content_client_of(context));if (images == m_animated_images.end())return;for (auto& image_entry : images->value) {@@ -577,7 +645,7 @@ void CompositorState::present_contexts_drawing_video_sink(CompositorStateWebCont{for (auto& context_entry : m_contexts) {auto& context = *context_entry.value;- if (&context.web_content_client() != &client)+ if (context.web_content_client_id() != client.web_content_client_id())continue;if (!context_is_effectively_visible(context))continue;@@ -595,7 +663,7 @@ void CompositorState::present_contexts_drawing_canvas(CompositorStateWebContentC{for (auto& context_entry : m_contexts) {auto& context = *context_entry.value;- if (&context.web_content_client() != &client)+ if (context.web_content_client_id() != client.web_content_client_id())continue;if (!context_is_effectively_visible(context) || !context.presenter().draws_canvas(canvas_id))continue;@@ -606,7 +674,7 @@ void CompositorState::present_contexts_drawing_canvas(CompositorStateWebContentCvoid CompositorState::resolve_video_sinks(ContextState& context){- auto& client = context.web_content_client();+ auto& client = web_content_client_of(context);for (auto const& resource_entry : context.presenter().resource_storage().video_sink_handles()) {auto* sink_state = video_sink_state(client, resource_entry.value);context.presenter().resource_storage().set_video_sink(Compositing::VideoSinkResourceId { resource_entry.key }, sink_state ? sink_state->sink : nullptr);@@ -617,7 +685,7 @@ bool CompositorState::video_sink_is_painted_by_any_context(CompositorStateWebCon{for (auto const& context_entry : m_contexts) {auto const& context = *context_entry.value;- if (&context.web_content_client() != client)+ if (context.web_content_client_id() != client->web_content_client_id())continue;for (auto const& resource_entry : context.presenter().resource_storage().video_sink_handles()) {if (resource_entry.value == handle)@@ -686,7 +754,7 @@ void CompositorState::update_video_sinks_for_display(Optional<u64> display_id)if (!context_is_effectively_visible(context))continue;for (auto const& resource_entry : context.presenter().resource_storage().video_sink_handles()) {- auto* sink_state = video_sink_state(context.web_content_client(), resource_entry.value);+ auto* sink_state = video_sink_state(web_content_client_of(context), resource_entry.value);if (sink_state != nullptr && sink_state->requires_updates) {vsync_scheduler_for_display(display_id).schedule(display_refresh_rate_for_context(context));break;@@ -948,7 +1016,7 @@ ContextState::ContextUpdateResult CompositorState::handle_mouse_event_in_nested_apply_context_update_result(nested_context_id, nested_context, nested_result);schedule_animation_frames_if_needed(nested_context);// Node ids are only unique within the process that made them.- bool ids_are_of_this_process = nested_context.is_owned_by(context.web_content_client());+ bool ids_are_of_this_process = nested_context.is_owned_by(context.web_content_client_id());return ContextState::ContextUpdateResult {.accepted = nested_result.accepted,.frame_to_present = move(frame_of_this_context),@@ -1122,7 +1190,7 @@ ContextState::ContextUpdateResult CompositorState::scroll_for_wheel_step(Web::Coif (!position.has_value())return ContextState::ContextUpdateResult::declined(Web::InputRoutingDecision::NestedContextUnavailable);step.position = *position;- auto applied_step = route_wheel_step_the_page_let_through(context_id, context, listener_context_id, *listener_context, step, {}, nullptr, now);+ auto applied_step = route_wheel_step_the_page_let_through(context_id, context, listener_context_id, *listener_context, step, {}, {}, now);result = move(applied_step.result);result.nested_context_hand_off = Web::InputRoutingDecision::HandedToNestedContext;presents_frame = applied_step.presents_frame;@@ -1153,7 +1221,7 @@ ContextState::ContextUpdateResult CompositorState::scroll_for_wheel_step(Web::Coreturn result;}-CompositorState::AppliedWheelStep CompositorState::apply_wheel_step_result(Web::CompositorContextId context_id, ContextState& context, ContextState::ContextUpdateResult const& result, CompositorStateWebContentClient const& reporting_client)+CompositorState::AppliedWheelStep CompositorState::apply_wheel_step_result(Web::CompositorContextId context_id, ContextState& context, ContextState::ContextUpdateResult const& result, WebContentClientId reporting_client){apply_context_update_result(context_id, context, result);schedule_animation_frames_if_needed(context);@@ -1188,7 +1256,7 @@ CompositorState::AppliedWheelStep CompositorState::hand_wheel_step_to_nested_conauto nested_result = nested_context->take_latched_wheel_step_from_containing_context(step, admission, now);if (nested_result.routing_decision == Web::InputRoutingDecision::NestedContextUnavailable)context.forget_wheel_gesture_latch();- return apply_wheel_step_result(nested_step.context_id, *nested_context, nested_result, context.web_content_client());+ return apply_wheel_step_result(nested_step.context_id, *nested_context, nested_result, context.web_content_client_id());}auto first_step = first_wheel_step_in_nested_contexts(context_id, *nested_step.hit, step.delta_in_css_pixels, step.wheel_delta_precision);@@ -1204,7 +1272,7 @@ CompositorState::AppliedWheelStep CompositorState::hand_wheel_step_to_nested_conif (taking_context->context && taking_context->route.kind != ContextState::FirstWheelStepRoute::Kind::Declined) {step.position = taking_context->position;auto nested_result = taking_context->context->take_first_wheel_step_from_containing_context(taking_context->route, step, now);- applied_step = apply_wheel_step_result(taking_context->context_id, *taking_context->context, nested_result, context.web_content_client());+ applied_step = apply_wheel_step_result(taking_context->context_id, *taking_context->context, nested_result, context.web_content_client_id());context.latch_wheel_gesture_to_nested_context(taking_context->context_id, applied_step.result.routed_scroller, step.scroll_gesture_phase);} else {applied_step.result = ContextState::ContextUpdateResult::declined(taking_context->route.decision);@@ -1256,15 +1324,15 @@ CompositorState::FirstWheelStepInNestedContexts CompositorState::first_wheel_ste// The page of one process scrolls a context of another process only by what the UI left to the page in the gesture, so// that a page cannot scroll the document around it at will.-static bool page_may_scroll_in(ContextState const& context, ContextState& routing_context, CompositorStateWebContentClient const* page_client, ContextState::WheelStep const& step)+static bool page_may_scroll_in(ContextState const& context, ContextState& routing_context, Optional<WebContentClientId> page_client, ContextState::WheelStep const& step){- return !page_client || context.is_owned_by(*page_client) || routing_context.take_wheel_delta_left_to_the_page(step.delta_in_css_pixels);+ return !page_client.has_value() || context.is_owned_by(*page_client) || routing_context.take_wheel_delta_left_to_the_page(step.delta_in_css_pixels);}-CompositorState::AppliedWheelStep CompositorState::route_wheel_step_the_page_let_through(Web::CompositorContextId routing_context_id, ContextState& routing_context, Web::CompositorContextId listener_context_id, ContextState& listener_context, ContextState::WheelStep step, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, CompositorStateWebContentClient const* page_client, MonotonicTime now)+CompositorState::AppliedWheelStep CompositorState::route_wheel_step_the_page_let_through(Web::CompositorContextId routing_context_id, ContextState& routing_context, Web::CompositorContextId listener_context_id, ContextState& listener_context, ContextState::WheelStep step, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, Optional<WebContentClientId> page_client, MonotonicTime now){using Kind = ContextState::FirstWheelStepRoute::Kind;- auto const& reporting_client = page_client ? *page_client : routing_context.web_content_client();+ auto const& reporting_client = page_client.has_value() ? *page_client : routing_context.web_content_client_id();auto declined = [](Web::InputRoutingDecision decision) {return AppliedWheelStep { .result = ContextState::ContextUpdateResult::declined(decision) };};@@ -1285,7 +1353,7 @@ CompositorState::AppliedWheelStep CompositorState::route_wheel_step_the_page_letif (!page_may_scroll_in(*context, routing_context, page_client, step))return declined(Web::InputRoutingDecision::StepExceedsInputLeftToThePage);auto nested_result = context->take_first_wheel_step_from_containing_context(route, step, now);- auto latched_scroller = context->is_owned_by(routing_context.web_content_client()) ? nested_result.routed_scroller : Optional<Web::AsyncScrollNodeStableID> {};+ auto latched_scroller = context->is_owned_by(routing_context.web_content_client_id()) ? nested_result.routed_scroller : Optional<Web::AsyncScrollNodeStableID> {};routing_context.latch_wheel_gesture_to_nested_context(context_id, latched_scroller, step.scroll_gesture_phase);return apply_wheel_step_result(context_id, *context, nested_result, reporting_client);}@@ -1416,10 +1484,10 @@ Compositing::WheelEventAnswer CompositorState::take_wheel_event_from_main_threadif (routing == Compositing::WheelEventRouting::AfterDispatch)return { .wheel_gesture_mark = noted.wheel_gesture_mark };auto result = scroll_for_wheel_step(context_id, *context, event, WheelStepOrigin::MainThread, noted.is_first_wheel_event_with_delta, operation_tracking, now);- return wheel_event_answer_for(apply_wheel_step_result(context_id, *context, result, context->web_content_client()), noted.wheel_gesture_mark);+ return wheel_event_answer_for(apply_wheel_step_result(context_id, *context, result, context->web_content_client_id()), noted.wheel_gesture_mark);}-Compositing::WheelEventAnswer CompositorState::scroll_for_wheel_event_the_page_let_through(Web::CompositorContextId listener_context_id, Compositing::WheelStepLetThrough const& let_through, Compositing::AsyncScrollOperationTracking operation_tracking, CompositorStateWebContentClient const& page_client)+Compositing::WheelEventAnswer CompositorState::scroll_for_wheel_event_the_page_let_through(Web::CompositorContextId listener_context_id, Compositing::WheelStepLetThrough const& let_through, Compositing::AsyncScrollOperationTracking operation_tracking, WebContentClientId page_client){auto now = MonotonicTime::now();auto* listener_context = context_if_present(listener_context_id);@@ -1472,18 +1540,18 @@ Compositing::WheelEventAnswer CompositorState::scroll_for_wheel_event_the_page_lrouting_context->forget_wheel_latch_of_gesture(gesture_id);return declined(Web::InputRoutingDecision::NestedContextUnavailable);}- if (!page_may_scroll_in(*nested_context, *routing_context, &page_client, step))+ if (!page_may_scroll_in(*nested_context, *routing_context, page_client, step))return declined(Web::InputRoutingDecision::StepExceedsInputLeftToThePage);auto nested_result = nested_context->take_latched_wheel_step_from_containing_context(step, ContextState::WheelStepAdmission::LetThroughByThePage, now);return answer(apply_wheel_step_result(*nested_context_id, *nested_context, nested_result, page_client));}- if (!page_may_scroll_in(*routing_context, *routing_context, &page_client, step))+ if (!page_may_scroll_in(*routing_context, *routing_context, page_client, step))return declined(Web::InputRoutingDecision::StepExceedsInputLeftToThePage);if (auto result = routing_context->scroll_for_latched_wheel_step_the_page_let_through(step, now); result.has_value())return answer(apply_wheel_step_result(*routing_context_id, *routing_context, *result, page_client));}- return answer(route_wheel_step_the_page_let_through(*routing_context_id, *routing_context, listener_context_id, *listener_context, step, scroll_chain, &page_client, now));+ return answer(route_wheel_step_the_page_let_through(*routing_context_id, *routing_context, listener_context_id, *listener_context, step, scroll_chain, page_client, now));}void CompositorState::forget_wheel_gesture_the_page_canceled(Web::CompositorContextId listener_context_id, u64 gesture_id)@@ -1529,11 +1597,9 @@ Compositing::PendingAsyncScrollUpdates CompositorState::take_pending_async_scrolreturn context->take_pending_async_scroll_updates();}-void CompositorState::publish_pending_async_scroll_updates(Web::CompositorContextId context_id, ContextState& context)+void CompositorState::publish_pending_async_scroll_updates(Web::CompositorContextId, ContextState& context){- if (!context.has_pending_async_scroll_updates())- return;- context.web_content_client().async_scroll_updates(context_id, context.take_pending_async_scroll_updates());+ context.publish_pending_async_scroll_updates();}void CompositorState::viewport_size_updated(Web::CompositorContextId context_id, Gfx::IntSize viewport_size, double device_pixel_ratio, Compositing::WindowResizingInProgress window_resize_in_progress)@@ -1663,7 +1729,7 @@ void CompositorState::request_rendering_opportunity(Web::CompositorContextId conframe_time.has_value() && context->rendering_opportunity_is_due(*frame_time, display_refresh_rate)) {auto frame_interval = context->rendering_opportunity_frame_interval(display_refresh_rate);context->did_deliver_rendering_opportunity(*frame_time);- context->web_content_client().rendering_opportunity(context_id, frame_time->nanoseconds(), frame_interval);+ web_content_client_of(*context).rendering_opportunity(context_id, frame_time->nanoseconds(), frame_interval);return;}@@ -1687,7 +1753,7 @@ void CompositorState::hurry_rendering_opportunity(Web::CompositorContextId conteauto frame_interval = context->rendering_opportunity_frame_interval(display_refresh_rate);auto frame_time = MonotonicTime::now();context->did_deliver_rendering_opportunity(frame_time);- context->web_content_client().rendering_opportunity(context_id, frame_time.nanoseconds(), frame_interval);+ web_content_client_of(*context).rendering_opportunity(context_id, frame_time.nanoseconds(), frame_interval);}void CompositorState::present_frame(Web::CompositorContextId context_id, Gfx::IntRect viewport_rect)@@ -1866,7 +1932,7 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,if (context.rendering_opportunity_is_due(frame_time, display_refresh_rate)) {auto frame_interval = context.rendering_opportunity_frame_interval(display_refresh_rate);context.did_deliver_rendering_opportunity(frame_time);- context.web_content_client().rendering_opportunity(context_id, frame_time.nanoseconds(), frame_interval);+ web_content_client_of(context).rendering_opportunity(context_id, frame_time.nanoseconds(), frame_interval);} else {vsync_scheduler_for_display(display_id).schedule(display_refresh_rate);}@@ -1896,7 +1962,7 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,if (context.clock_tick_is_due(frame_time, display_refresh_rate)) {auto frame_interval = context.clock_tick_interval(display_refresh_rate);context.did_deliver_clock_tick(frame_time);- context.web_content_client().clock_tick(context_id, frame_time.nanoseconds(), frame_interval, context.scroll_offsets());+ web_content_client_of(context).clock_tick(context_id, frame_time.nanoseconds(), frame_interval, context.scroll_offsets());} else {vsync_scheduler_for_display(display_id).schedule(display_refresh_rate);}@@ -2181,7 +2247,7 @@ Optional<Compositing::FirstWheelStepRouteForTesting> CompositorState::route_firsif (!taking_context.has_value())return context->route_first_wheel_step_for_testing(position, delta_in_css_pixels, Compositing::NestedContextRegions::Ignore);// Node ids are only unique within the process that made them.- bool ids_are_of_this_process = taking_context->context && taking_context->context->is_owned_by(context->web_content_client());+ bool ids_are_of_this_process = taking_context->context && taking_context->context->is_owned_by(context->web_content_client_id());Compositing::FirstWheelStepRouteForTesting route { .route = { taking_context->route.decision }, .document_id = {} };if (ids_are_of_this_process) {route.route.scroller = taking_context->route.scroller;diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.hindex bc694d72cf4..ba7fcacd04d 100644--- a/Services/Compositor/CompositorState.h+++ b/Services/Compositor/CompositorState.h@@ -6,6 +6,7 @@#pragma once+#include <AK/Array.h>#include <AK/DoublyLinkedList.h>#include <AK/HashMap.h>#include <AK/NonnullRefPtr.h>@@ -14,6 +15,7 @@#include <AK/RefCounted.h>#include <Compositor/AnimatedImage.h>#include <Compositor/CanvasSurfaceRegistry.h>+#include <Compositor/CompositorCoreHost.h>#include <Compositor/ContextState.h>#include <Compositor/DisplayListPlayerSkia.h>#include <Compositor/SkiaBackendContext.h>@@ -58,18 +60,11 @@ class CompositorStateWebContentClient {public:virtual ~CompositorStateWebContentClient() = default;- virtual void dispatch_mouse_event_to_web_content(u64 page_id, Web::MouseEvent const&) = 0;- virtual void dispatch_key_event_to_web_content(u64 page_id, Web::KeyEvent const&) = 0;- virtual void dispatch_pinch_event_to_web_content(u64 page_id, Web::PinchEvent const&) = 0;- virtual void request_rendering_update() = 0;+ virtual WebContentClientId web_content_client_id() const = 0;+ virtual void post_message_to_web_content(IPC::MessageBuffer&) = 0;+ virtual void post_message_to_render_clock(IPC::MessageBuffer&) = 0;virtual void rendering_opportunity(Web::CompositorContextId, i64 frame_time_nanoseconds, double frame_interval_milliseconds) = 0;virtual void clock_tick(Web::CompositorContextId, i64 frame_time_nanoseconds, double frame_interval_milliseconds, Vector<Web::CompositorScrollOffset> const& scroll_offsets) = 0;- virtual void pointer_moved(Web::CompositorContextId, Web::DevicePixelPoint, u32 /* buttons */, bool /* scrolled_since_frame */, u64 /* input_event_id */) { }- virtual void pointer_left(Web::CompositorContextId, u64 /* input_event_id */) { }- virtual void pointer_rests_on_moving_content(Web::CompositorContextId) { }- virtual void async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates const&) = 0;- virtual void animated_content_moved_under_pointer(Web::CompositorContextId, i64 /* frame_time_nanoseconds */) { }- virtual void overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> const&) { }virtual void create_video_edge(Media::VideoSinkHandle) = 0;virtual void release_video_edge(Media::VideoSinkHandle) = 0;virtual void video_sink_presented_frame(Media::VideoSinkHandle, RefPtr<Media::VideoFrame>, Media::DisplayingVideoSinkFrameCounts) { }@@ -80,7 +75,9 @@ public:virtual Compositing::CanvasSurfaceOwnerId canvas_surface_owner_id() const = 0;};-class CompositorState final : public RefCounted<CompositorState> {+class CompositorState final+ : public RefCounted<CompositorState>+ , public CompositorCoreHost {public:static NonnullRefPtr<CompositorState> create(RefPtr<Gfx::SkiaBackendContext>);~CompositorState();@@ -107,7 +104,8 @@ public:void unregister_presentation(CompositorStateClient&);void bind_presentation(Web::CompositorContextId, CompositorStateClient&);CompositorStateClient* presentation_for_context(Web::CompositorContextId) const;- ContextOwnerCheckResult check_context_owner(Web::CompositorContextId, CompositorStateWebContentClient&);+ WebContentClientId register_web_content_client(CompositorStateWebContentClient&);+ ContextOwnerCheckResult check_context_owner(Web::CompositorContextId, WebContentClientId);void destroy_contexts_for_web_content_client(CompositorStateWebContentClient&);RefPtr<Gfx::SkiaBackendContext> skia_backend_context() const { return m_skia_backend_context; }@@ -148,7 +146,7 @@ public:// Scrolls by a step that the page of the context dispatched and did not cancel. The context that routes the// gesture is the nearest one, from that context out to the presenting one, that noted the gesture, and the steps the// compositor still has to route of the gesture no longer wait for the page.- Compositing::WheelEventAnswer scroll_for_wheel_event_the_page_let_through(Web::CompositorContextId, Compositing::WheelStepLetThrough const&, Compositing::AsyncScrollOperationTracking, CompositorStateWebContentClient const& page_client);+ Compositing::WheelEventAnswer scroll_for_wheel_event_the_page_let_through(Web::CompositorContextId, Compositing::WheelStepLetThrough const&, Compositing::AsyncScrollOperationTracking, WebContentClientId page_client);void forget_wheel_gesture_the_page_canceled(Web::CompositorContextId, u64 gesture_id);void apply_scroll_requests(Web::CompositorContextId, ReadonlySpan<Compositing::ScrollRequest>);void viewport_size_updated(Web::CompositorContextId, Gfx::IntSize, double device_pixel_ratio, Compositing::WindowResizingInProgress);@@ -189,6 +187,15 @@ public:private:CompositorState(RefPtr<Gfx::SkiaBackendContext>);+ CompositorStateWebContentClient* web_content_client_if_present(WebContentClientId) const;+ CompositorStateWebContentClient& web_content_client_of(ContextState const&);+ virtual void post_message_to_web_content(WebContentClientId, IPC::MessageBuffer&) override;+ virtual void post_message_to_render_clock_of_web_content(WebContentClientId, IPC::MessageBuffer&) override;+ virtual void request_display_ticks(Web::CompositorContextId) override;+ virtual void set_timer(Web::CompositorContextId, ContextTimer, AK::Duration delay) override;+ virtual void cancel_timer(Web::CompositorContextId, ContextTimer) override;+ void context_timer_fired(Web::CompositorContextId, ContextTimer);+struct PendingAsyncPresent {PendingAsyncPresent(Web::CompositorContextId context_id, Gfx::IntRect viewport_rect, Gfx::IntRect damage_rect, i32 bitmap_id, double device_pixel_ratio): context_id(context_id)@@ -271,7 +278,7 @@ private:bool presents_frame { false };};// A process only knows the ids of its own nodes, and only follows the operations of its own contexts.- AppliedWheelStep apply_wheel_step_result(Web::CompositorContextId, ContextState&, ContextState::ContextUpdateResult const&, CompositorStateWebContentClient const& reporting_client);+ AppliedWheelStep apply_wheel_step_result(Web::CompositorContextId, ContextState&, ContextState::ContextUpdateResult const&, WebContentClientId reporting_client);static Compositing::WheelEventAnswer wheel_event_answer_for(AppliedWheelStep const&, Optional<Web::WheelGestureMark>);AppliedWheelStep hand_wheel_step_to_nested_context(Web::CompositorContextId, ContextState&, Web::MouseEvent const&, ContextState::NestedContextWheelStep const&, ContextState::WheelEventListenerGate const&, Compositing::AsyncScrollOperationTracking, MonotonicTime now);struct NestedContextTakingWheelStep {@@ -294,7 +301,7 @@ private:// scrollers the page found around the target, and on to the contexts around it for what a context passes on, up to// the routing context, which latches the gesture. A page of another process than a context's scrolls it only by// what the UI left to the page in the gesture.- AppliedWheelStep route_wheel_step_the_page_let_through(Web::CompositorContextId routing_context_id, ContextState& routing_context, Web::CompositorContextId listener_context_id, ContextState& listener_context, ContextState::WheelStep, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, CompositorStateWebContentClient const* page_client, MonotonicTime now);+ AppliedWheelStep route_wheel_step_the_page_let_through(Web::CompositorContextId routing_context_id, ContextState& routing_context, Web::CompositorContextId listener_context_id, ContextState& listener_context, ContextState::WheelStep, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, Optional<WebContentClientId> page_client, MonotonicTime now);// The nearest context, from the given one out to the presenting one, that noted the gesture.Optional<Web::CompositorContextId> routing_context_of_wheel_gesture(Web::CompositorContextId, u64 gesture_id);// The scrollbars of a context nested in the presenting context `context_id` take the pointer over that context's@@ -329,6 +336,9 @@ private:void check_gpu_completions();HashMap<Web::CompositorContextId, OwnPtr<ContextState>> m_contexts;+ u64 m_next_web_content_client_id { 1 };+ HashMap<WebContentClientId, CompositorStateWebContentClient*> m_web_content_clients;+ HashMap<Web::CompositorContextId, HashMap<ContextTimer, NonnullRefPtr<Core::Timer>>> m_context_timers;DoublyLinkedList<PendingAsyncPresent> m_pending_async_presents;RefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cppindex 5d7f727e239..04245a5223b 100644--- a/Services/Compositor/ConnectionFromWebContent.cpp+++ b/Services/Compositor/ConnectionFromWebContent.cpp@@ -20,6 +20,7 @@ namespace Compositor {ConnectionFromWebContent::ConnectionFromWebContent(NonnullOwnPtr<IPC::Transport> transport, NonnullRefPtr<CompositorState> compositor_state, int client_id): IPC::ConnectionFromClient<CompositorWebContentClientEndpoint, CompositorWebContentServerEndpoint>(*this, move(transport), client_id), m_compositor_state(move(compositor_state))+ , m_web_content_client_id(m_compositor_state->register_web_content_client(*this)), m_canvas_host(m_compositor_state->skia_backend_context(), m_compositor_state->canvas_surface_registry(), m_video_frame_holds){}@@ -72,24 +73,6 @@ void ConnectionFromWebContent::clock_tick(Web::CompositorContextId context_id, im_render_clock_connection->async_clock_tick(context_id, frame_time_nanoseconds, frame_interval_milliseconds, scroll_offsets);}-void ConnectionFromWebContent::pointer_moved(Web::CompositorContextId context_id, Web::DevicePixelPoint position, u32 buttons, bool scrolled_since_frame, u64 input_event_id)-{- if (m_render_clock_connection)- m_render_clock_connection->async_pointer_moved(context_id, position, buttons, scrolled_since_frame, input_event_id);-}--void ConnectionFromWebContent::pointer_left(Web::CompositorContextId context_id, u64 input_event_id)-{- if (m_render_clock_connection)- m_render_clock_connection->async_pointer_left(context_id, input_event_id);-}--void ConnectionFromWebContent::pointer_rests_on_moving_content(Web::CompositorContextId context_id)-{- if (m_render_clock_connection)- m_render_clock_connection->async_pointer_rests_on_moving_content(context_id);-}-void ConnectionFromWebContent::drop_image_decoder(){if (!m_image_decoder)@@ -220,49 +203,25 @@ void ConnectionFromWebContent::notify_compositor_lost()async_did_lose_compositor();}-void ConnectionFromWebContent::request_rendering_update()-{- async_request_rendering_update();-}--void ConnectionFromWebContent::rendering_opportunity(Web::CompositorContextId context_id, i64 frame_time_nanoseconds, double frame_interval_milliseconds)-{- async_rendering_opportunity(context_id, frame_time_nanoseconds, frame_interval_milliseconds);-}--void ConnectionFromWebContent::async_scroll_updates(Web::CompositorContextId context_id, Compositing::PendingAsyncScrollUpdates const& updates)-{- async_async_scroll_updates(context_id, updates);-}--void ConnectionFromWebContent::animated_content_moved_under_pointer(Web::CompositorContextId context_id, i64 frame_time_nanoseconds)-{- async_animated_content_moved_under_pointer(context_id, frame_time_nanoseconds);-}--void ConnectionFromWebContent::overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> const& visibilities)-{- async_overlay_scrollbar_visibilities_changed(visibilities);-}--void ConnectionFromWebContent::dispatch_mouse_event_to_web_content(u64 page_id, Web::MouseEvent const& event)+void ConnectionFromWebContent::post_message_to_web_content(IPC::MessageBuffer& buffer){- async_mouse_event(page_id, event);+ (void)post_message(buffer);}-void ConnectionFromWebContent::dispatch_key_event_to_web_content(u64 page_id, Web::KeyEvent const& event)+void ConnectionFromWebContent::post_message_to_render_clock(IPC::MessageBuffer& buffer){- async_key_event(page_id, event);+ if (m_render_clock_connection)+ (void)m_render_clock_connection->post_message(buffer);}-void ConnectionFromWebContent::dispatch_pinch_event_to_web_content(u64 page_id, Web::PinchEvent const& event)+void ConnectionFromWebContent::rendering_opportunity(Web::CompositorContextId context_id, i64 frame_time_nanoseconds, double frame_interval_milliseconds){- async_pinch_event(page_id, event);+ async_rendering_opportunity(context_id, frame_time_nanoseconds, frame_interval_milliseconds);}bool ConnectionFromWebContent::context_is_owned_by_this_connection(Web::CompositorContextId context_id){- switch (m_compositor_state->check_context_owner(context_id, *this)) {+ switch (m_compositor_state->check_context_owner(context_id, web_content_client_id())) {case CompositorState::ContextOwnerCheckResult::OwnedByClient:return true;case CompositorState::ContextOwnerCheckResult::ContextUnavailable:@@ -601,7 +560,7 @@ Messages::CompositorWebContentServer::WheelEventLetThroughResponse ConnectionFro{if (!context_is_owned_by_this_connection(context_id) || !is_valid_wheel_step_let_through(step))return Compositing::WheelEventAnswer {};- return m_compositor_state->scroll_for_wheel_event_the_page_let_through(context_id, step, operation_tracking, *this);+ return m_compositor_state->scroll_for_wheel_event_the_page_let_through(context_id, step, operation_tracking, web_content_client_id());}void ConnectionFromWebContent::wheel_event_canceled(Web::CompositorContextId context_id, u64 wheel_gesture_id)diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.hindex 7aedc0ba3d8..1a435242cdd 100644--- a/Services/Compositor/ConnectionFromWebContent.h+++ b/Services/Compositor/ConnectionFromWebContent.h@@ -101,18 +101,11 @@ private:virtual void present_frame(Web::CompositorContextId, Gfx::IntRect viewport_rect) override;virtual void request_screenshot(Web::CompositorContextId, Compositing::ScreenshotRequestId request_id, Gfx::ShareableBitmap target_bitmap) override;- virtual void dispatch_mouse_event_to_web_content(u64 page_id, Web::MouseEvent const&) override;- virtual void dispatch_key_event_to_web_content(u64 page_id, Web::KeyEvent const&) override;- virtual void dispatch_pinch_event_to_web_content(u64 page_id, Web::PinchEvent const&) override;- virtual void request_rendering_update() override;+ virtual WebContentClientId web_content_client_id() const override { return m_web_content_client_id; }+ virtual void post_message_to_web_content(IPC::MessageBuffer&) override;+ virtual void post_message_to_render_clock(IPC::MessageBuffer&) override;virtual void rendering_opportunity(Web::CompositorContextId, i64 frame_time_nanoseconds, double frame_interval_milliseconds) override;virtual void clock_tick(Web::CompositorContextId, i64 frame_time_nanoseconds, double frame_interval_milliseconds, Vector<Web::CompositorScrollOffset> const& scroll_offsets) override;- virtual void pointer_moved(Web::CompositorContextId, Web::DevicePixelPoint, u32 buttons, bool scrolled_since_frame, u64 input_event_id) override;- virtual void pointer_left(Web::CompositorContextId, u64 input_event_id) override;- virtual void pointer_rests_on_moving_content(Web::CompositorContextId) override;- virtual void async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates const&) override;- virtual void animated_content_moved_under_pointer(Web::CompositorContextId, i64 frame_time_nanoseconds) override;- virtual void overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> const&) override;virtual void create_video_edge(Media::VideoSinkHandle) override;virtual void release_video_edge(Media::VideoSinkHandle) override;virtual void request_animated_image_frames(AnimatedImage::FrameRequest const&) override;@@ -123,6 +116,7 @@ private:bool context_is_owned_by_this_connection(Web::CompositorContextId);NonnullRefPtr<CompositorState> m_compositor_state;+ WebContentClientId m_web_content_client_id;VideoFrameHolds m_video_frame_holds;CanvasHost m_canvas_host;diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cppindex ce9fff999e5..956228f039b 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -9,14 +9,14 @@#include <AK/Math.h>#include <AK/ScopeGuard.h>#include <AK/StdLibExtras.h>-#include <Compositor/CompositorState.h>+#include <Compositor/CompositorWebContentClientEndpoint.h>#include <Compositor/ContextState.h>#include <Compositor/DisplayListPlayerSkia.h>#include <Compositor/PaintingSurface.h>#include <Compositor/PausedDebuggerOverlay.h>+#include <Compositor/RenderClockClientEndpoint.h>#include <Compositor/SkiaUtils.h>#include <LibCompositing/DisplayList/DisplayListDamage.h>-#include <LibCore/Timer.h>#include <LibGfx/Bitmap.h>#include <LibWebCommon/Page/InputEvent.h>#include <core/SkCanvas.h>@@ -59,32 +59,60 @@ static void clamp_visual_viewport_transform_to_viewport(Compositing::TransformWitransform.matrix[1, 3] = clamp(transform.matrix[1, 3], min_y, 0.0f);}-ContextState::ContextState(Web::CompositorContextId context_id, Optional<u64> page_id, CompositorStateWebContentClient& web_content_client, OwnedCanvasSurfaces canvas_surfaces, Function<void(Gfx::IntRect)> schedule_caret_repaint, Function<void()> request_animation_frames)- : m_web_content_client(web_content_client)+ContextState::ContextState(Web::CompositorContextId context_id, Optional<u64> page_id, WebContentClientId web_content_client_id, CompositorCoreHost& host, OwnedCanvasSurfaces canvas_surfaces)+ : m_host(host)+ , m_web_content_client_id(web_content_client_id), m_context_id(context_id), m_page_id(page_id), m_presenter(canvas_surfaces, page_id.has_value()), m_presents_to_client(page_id.has_value())- , m_caret_blink_timer([this] { return damage_rect_of_blinking_carets(); }, move(schedule_caret_repaint))- , m_request_animation_frames(move(request_animation_frames)){}-ContextState::~ContextState()+bool ContextState::is_owned_by(WebContentClientId web_content_client_id) const{- if (m_scrollbar_paging_timer) {- m_scrollbar_paging_timer->on_timeout = {};- m_scrollbar_paging_timer->stop();- }- if (m_scrollbar_fade_out_timer) {- m_scrollbar_fade_out_timer->on_timeout = {};- m_scrollbar_fade_out_timer->stop();- }+ return m_web_content_client_id == web_content_client_id;+}++void ContextState::request_display_ticks_if_needed(MonotonicTime now)+{+ if (needs_animation_frames(now))+ m_host.request_display_ticks(m_context_id);}-bool ContextState::is_owned_by(CompositorStateWebContentClient const& web_content_client) const+Optional<Gfx::IntRect> ContextState::timer_fired(ContextTimer timer, MonotonicTime now){- return &m_web_content_client == &web_content_client;+ switch (timer) {+ case ContextTimer::ScrollStepGestureInput:+ end_scroll_step_gestures_whose_input_ran_out(now);+ break;+ case ContextTimer::ScrollbarPaging:+ m_scrollbar_paging_timer_is_armed = false;+ // Paging ends with the press, and with the scrollbar the press holds.+ if (!m_scrollbar_paging.has_value() || !m_scrollbar_controller.has_captured_scrollbar()) {+ stop_scrollbar_paging();+ return {};+ }+ // Once the thumb reaches the pointer, paging waits for the pointer to move.+ if (!page_captured_scrollbar(now).has_value())+ return {};+ request_rendering_update();+ request_display_ticks_if_needed(now);+ m_host.set_timer(m_context_id, ContextTimer::ScrollbarPaging, scrollbar_paging_repeat_interval);+ m_scrollbar_paging_timer_is_armed = true;+ break;+ case ContextTimer::ScrollbarFadeOut:+ request_display_ticks_if_needed(now);+ break;+ case ContextTimer::CaretBlink: {+ auto damage_rect = damage_rect_of_blinking_carets();+ schedule_next_caret_blink(now);+ if (!damage_rect.is_empty())+ return damage_rect;+ break;+ }+ }+ return {};}void ContextState::request_rendering_update()@@ -92,23 +120,23 @@ void ContextState::request_rendering_update()// The rendering update this asks for adopts the scroll updates it finds pushed by then. What is pending here goes// ahead of the request on the wire, so that an update run on the request never misses it.if (has_pending_async_scroll_updates())- m_web_content_client.async_scroll_updates(m_context_id, take_pending_async_scroll_updates());- m_web_content_client.request_rendering_update();+ post_to_web_content<Messages::CompositorWebContentClient::AsyncScrollUpdates>(m_context_id, take_pending_async_scroll_updates());+ post_to_web_content<Messages::CompositorWebContentClient::RequestRenderingUpdate>();}void ContextState::dispatch_mouse_event_to_web_content(Web::MouseEvent const& event, bool nested_context_scrolled_since_last_frame){VERIFY(m_page_id.has_value());- m_web_content_client.dispatch_mouse_event_to_web_content(*m_page_id, event);+ post_to_web_content<Messages::CompositorWebContentClient::MouseEvent>(*m_page_id, event);// The render clock hears where the pointer went too, without waiting for WebContent's main thread, so that hover// can follow the pointer while that thread runs a task. The lanes hit test it in the frames on screen, which a// scroll since, here or in a nested context, has moved. A button going up ends the drag a lane follows, whether or// not a move comes after it.if (event.type == Web::MouseEvent::Type::MouseMove || event.type == Web::MouseEvent::Type::MouseUp)- m_web_content_client.pointer_moved(m_context_id, event.position, to_underlying(event.buttons), scrolled_since_last_frame() || nested_context_scrolled_since_last_frame, event.id);+ post_to_render_clock_of_web_content<Messages::RenderClockClient::PointerMoved>(m_context_id, event.position, to_underlying(event.buttons), scrolled_since_last_frame() || nested_context_scrolled_since_last_frame, event.id);else if (event.type == Web::MouseEvent::Type::MouseLeave)- m_web_content_client.pointer_left(m_context_id, event.id);+ post_to_render_clock_of_web_content<Messages::RenderClockClient::PointerLeft>(m_context_id, event.id);}bool ContextState::scrolled_since_last_frame() const@@ -119,13 +147,13 @@ bool ContextState::scrolled_since_last_frame() constvoid ContextState::dispatch_key_event_to_web_content(Web::KeyEvent const& event){VERIFY(m_page_id.has_value());- m_web_content_client.dispatch_key_event_to_web_content(*m_page_id, event);+ post_to_web_content<Messages::CompositorWebContentClient::KeyEvent>(*m_page_id, event);}void ContextState::dispatch_pinch_event_to_web_content(Web::PinchEvent const& event){VERIFY(m_page_id.has_value());- m_web_content_client.dispatch_pinch_event_to_web_content(*m_page_id, event);+ post_to_web_content<Messages::CompositorWebContentClient::PinchEvent>(*m_page_id, event);}void ContextState::stop_presenting_to_client()@@ -153,7 +181,7 @@ void ContextState::install_display_list_update(m_keyboard_scroll_controller.forget_target();m_scroll_state_snapshot = move(scroll_state_snapshot);m_scroll_state_snapshot.set_node_count(m_scene.visual_context_tree()->spatial_node_count());- m_caret_blink_timer.did_install_display_list(*m_scene.display_list());+ restart_caret_blink_for(*m_scene.display_list(), now);auto async_scrolling_state = Compositing::async_scrolling_state_from_display_list(*m_scene.display_list());auto async_scrolling_viewport_rect = async_scrolling_state.viewport_rect;@@ -185,6 +213,39 @@ void ContextState::install_display_list_update(adopt_keyboard_scroll_state(metadata->keyboard_scroll_state);}+// Repaints the blinking caret of a display list each time its blink cycle turns it on or off.+void ContextState::restart_caret_blink_for(Compositing::DisplayList const& display_list, MonotonicTime now)+{+ Optional<i64> blink_cycle_start_time_ns;+ display_list.for_each_caret([&](auto, auto, auto const& caret) {+ if (caret.should_blink)+ blink_cycle_start_time_ns = caret.blink_cycle_start_time_ns;+ });++ if (blink_cycle_start_time_ns == m_caret_blink_cycle_start_time_ns)+ return;+ m_caret_blink_cycle_start_time_ns = blink_cycle_start_time_ns;++ m_host.cancel_timer(m_context_id, ContextTimer::CaretBlink);+ if (!m_caret_blink_cycle_start_time_ns.has_value())+ return;++ schedule_next_caret_blink(now);+}++void ContextState::schedule_next_caret_blink(MonotonicTime now)+{+ if (!m_caret_blink_cycle_start_time_ns.has_value())+ return;++ auto now_ns = now.nanoseconds();+ auto elapsed_ns = now_ns > *m_caret_blink_cycle_start_time_ns+ ? now_ns - *m_caret_blink_cycle_start_time_ns+ : 0;+ auto delay_ns = Compositing::caret_blink_interval_ns - elapsed_ns % Compositing::caret_blink_interval_ns;+ m_host.set_timer(m_context_id, ContextTimer::CaretBlink, AK::Duration::from_nanoseconds(delay_ns));+}+Gfx::IntRect ContextState::damage_rect_of_blinking_carets(){if (!m_scene.display_list() || !m_scene.visual_context_tree().has_value())@@ -567,24 +628,8 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event_at(Web::Mouseresult.frame_to_present = *frame_to_present;result.should_request_rendering_update = true;}- if (!m_scrollbar_paging_timer) {- m_scrollbar_paging_timer = Core::Timer::create_single_shot(scrollbar_paging_initial_delay, [this] {- auto now = MonotonicTime::now();- // Paging ends with the press, and with the scrollbar the press holds.- if (!m_scrollbar_paging.has_value() || !m_scrollbar_controller.has_captured_scrollbar()) {- stop_scrollbar_paging();- return;- }- // Once the thumb reaches the pointer, paging waits for the pointer to move.- if (!page_captured_scrollbar(now).has_value())- return;- request_rendering_update();- if (m_request_animation_frames)- m_request_animation_frames();- m_scrollbar_paging_timer->restart(scrollbar_paging_repeat_interval);- });- }- m_scrollbar_paging_timer->restart(scrollbar_paging_initial_delay);+ m_host.set_timer(m_context_id, ContextTimer::ScrollbarPaging, scrollbar_paging_initial_delay);+ m_scrollbar_paging_timer_is_armed = true;return result;}@@ -603,8 +648,10 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event_at(Web::MouseOptional<PendingFrame> frame_to_present;if (m_scrollbar_paging.has_value()) {m_scrollbar_paging->primary_position = drag->primary_position;- if (!m_scrollbar_paging_timer->is_active())- m_scrollbar_paging_timer->restart(scrollbar_paging_repeat_interval);+ if (!m_scrollbar_paging_timer_is_armed) {+ m_host.set_timer(m_context_id, ContextTimer::ScrollbarPaging, scrollbar_paging_repeat_interval);+ m_scrollbar_paging_timer_is_armed = true;+ }} else {frame_to_present = apply_scrollbar_drag(*drag, now);}@@ -2001,6 +2048,13 @@ bool ContextState::has_pending_async_scroll_updates() constreturn m_async_scroll_update_outbox.has_updates(user_scroll_gesture_state());}+void ContextState::publish_pending_async_scroll_updates()+{+ if (!has_pending_async_scroll_updates())+ return;+ post_to_web_content<Messages::CompositorWebContentClient::AsyncScrollUpdates>(m_context_id, take_pending_async_scroll_updates());+}+void ContextState::viewport_size_updated(Gfx::IntSize viewport_size){m_scene.forget_whether_animated_content_may_affect_viewport();@@ -2067,23 +2121,17 @@ void ContextState::update_scrollbar_visibility(MonotonicTime now)report_scrollbar_visibility_changes();// A hovered scrollbar starts to grow here, which needs display ticks before anything else asks for a frame.- if (m_request_animation_frames && m_scrollbar_controller.fades_need_frame(now))- m_request_animation_frames();+ if (m_scrollbar_controller.fades_need_frame(now))+ m_host.request_display_ticks(m_context_id);// The fade out runs on display ticks, which the wait before it does not need.auto fade_out_time = m_scrollbar_controller.next_fade_out_time();- if (!fade_out_time.has_value() || !m_request_animation_frames) {- if (m_scrollbar_fade_out_timer)- m_scrollbar_fade_out_timer->stop();+ if (!fade_out_time.has_value()) {+ m_host.cancel_timer(m_context_id, ContextTimer::ScrollbarFadeOut);return;}- if (!m_scrollbar_fade_out_timer) {- m_scrollbar_fade_out_timer = Core::Timer::create_single_shot(AK::Duration::zero(), [this] {- m_request_animation_frames();- });- }auto delay = max(AK::Duration::zero(), *fade_out_time - now);- m_scrollbar_fade_out_timer->restart(delay);+ m_host.set_timer(m_context_id, ContextTimer::ScrollbarFadeOut, delay);}// NB: This goes on the connection the compositor forwards input on, so the main thread knows which scrollbars have@@ -2093,7 +2141,7 @@ void ContextState::report_scrollbar_visibility_changes(){auto changes = m_scrollbar_controller.take_visibility_changes();if (!changes.is_empty())- m_web_content_client.overlay_scrollbar_visibilities_changed(changes);+ post_to_web_content<Messages::CompositorWebContentClient::OverlayScrollbarVisibilitiesChanged>(changes);}Gfx::IntRect ContextState::advance_scrollbar_fades_and_return_damage_rect(MonotonicTime frame_time)@@ -2270,14 +2318,16 @@ WheelGestureRouting::ResolvedLatch ContextState::resolve_wheel_scroll_latch(Web:Compositing::WheelHitTestResult ContextState::route_first_wheel_step(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Compositing::WheelStepDispatch wheel_step_dispatch, Compositing::NestedContextRegions nested_context_regions, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain){- Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> in_flight_destination_for;- if (wheel_delta_precision == Web::WheelDeltaPrecision::Discrete)- in_flight_destination_for = [this](auto stable_node_id) { return in_flight_wheel_destination(stable_node_id); };+ auto in_flight_destination_for = [this, wheel_delta_precision](Web::AsyncScrollNodeStableID stable_node_id) -> Optional<Gfx::FloatPoint> {+ if (wheel_delta_precision == Web::WheelDeltaPrecision::Discrete)+ return in_flight_wheel_destination(stable_node_id);+ return {};+ };for (auto stable_node_id : scroll_chain) {if (auto scroll_node_index = m_async_scroll_tree.scroll_node_index_for_stable_id(stable_node_id); scroll_node_index.has_value())- return m_async_scroll_tree.hit_test_result_for_scroll_node(*scroll_node_index, delta, in_flight_destination_for);+ return m_async_scroll_tree.hit_test_result_for_scroll_node(*scroll_node_index, delta, move(in_flight_destination_for));}- return m_async_scroll_tree.hit_test_scroll_node_for_wheel(m_scene.visual_context_tree_for_compositing(), position, delta, in_flight_destination_for, wheel_step_dispatch, nested_context_regions);+ return m_async_scroll_tree.hit_test_scroll_node_for_wheel(m_scene.visual_context_tree_for_compositing(), position, delta, move(in_flight_destination_for), wheel_step_dispatch, nested_context_regions);}ContextState::WheelGestureLatchAttempt ContextState::route_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Optional<u64> gesture_id, Compositing::WheelStepDispatch wheel_step_dispatch, Compositing::NestedContextRegions nested_context_regions, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain)@@ -2381,17 +2431,10 @@ void ContextState::schedule_end_of_scroll_step_gestures(MonotonicTime now){auto deadline = m_scroll_snap_controller.earliest_gesture_input_deadline();if (!deadline.has_value()) {- if (m_scroll_step_gesture_input_timer)- m_scroll_step_gesture_input_timer->stop();+ m_host.cancel_timer(m_context_id, ContextTimer::ScrollStepGestureInput);return;}- if (!m_scroll_step_gesture_input_timer) {- m_scroll_step_gesture_input_timer = Core::Timer::create_single_shot(AK::Duration::from_milliseconds(0), [this] {- auto now = MonotonicTime::now();- end_scroll_step_gestures_whose_input_ran_out(now);- });- }- m_scroll_step_gesture_input_timer->restart(max(*deadline - now, AK::Duration::zero()));+ m_host.set_timer(m_context_id, ContextTimer::ScrollStepGestureInput, max(*deadline - now, AK::Duration::zero()));}void ContextState::end_scroll_step_gestures_whose_input_ran_out(MonotonicTime now)@@ -2478,8 +2521,8 @@ ContextState::ActiveSmoothScrollAnimation* ContextState::running_scrollbar_pressvoid ContextState::stop_scrollbar_paging(){m_scrollbar_paging.clear();- if (m_scrollbar_paging_timer)- m_scrollbar_paging_timer->stop();+ m_host.cancel_timer(m_context_id, ContextTimer::ScrollbarPaging);+ m_scrollbar_paging_timer_is_armed = false;}Optional<PendingFrame> ContextState::apply_scrollbar_drag(ScrollbarController::Drag const& drag, MonotonicTime now)@@ -2561,8 +2604,8 @@ bool ContextState::advance_visual_animations(MonotonicTime now)auto animated_content_is_under_pointer = animations_are_active && m_pointer_position.has_value()&& m_scene.visual_context_tree_for_compositing().running_transform_animation_covers_point(now.nanoseconds(), *m_pointer_position, m_scroll_state_snapshot);if (animated_content_is_under_pointer || m_animated_content_was_under_pointer) {- m_web_content_client.animated_content_moved_under_pointer(m_context_id, now.nanoseconds());- m_web_content_client.pointer_rests_on_moving_content(m_context_id);+ post_to_web_content<Messages::CompositorWebContentClient::AnimatedContentMovedUnderPointer>(m_context_id, now.nanoseconds());+ post_to_render_clock_of_web_content<Messages::RenderClockClient::PointerRestsOnMovingContent>(m_context_id);}m_animated_content_was_under_pointer = animated_content_is_under_pointer;return animations_are_active;diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.hindex 054e65a7c53..0f206e1890c 100644--- a/Services/Compositor/ContextState.h+++ b/Services/Compositor/ContextState.h@@ -6,17 +6,18 @@#pragma once-#include <AK/Function.h>#include <AK/HashMap.h>#include <AK/Noncopyable.h>#include <AK/NonnullRefPtr.h>#include <AK/Optional.h>#include <AK/RefPtr.h>#include <AK/Span.h>+#include <AK/StdLibExtras.h>+#include <AK/Try.h>#include <AK/Vector.h>#include <Compositor/AsyncScrollUpdateOutbox.h>-#include <Compositor/CaretBlinkTimer.h>#include <Compositor/CompositedContext.h>+#include <Compositor/CompositorCoreHost.h>#include <Compositor/ContextPresenter.h>#include <Compositor/ContextScene.h>#include <Compositor/ElasticOverscrollController.h>@@ -54,8 +55,6 @@ class SkiaBackendContext;namespace Compositor {-class CompositorStateWebContentClient;-class ContextState {AK_MAKE_NONCOPYABLE(ContextState);AK_MAKE_NONMOVABLE(ContextState);@@ -158,11 +157,10 @@ public:Optional<Compositing::NestedContextHit> nested_context_hit {};};- ContextState(Web::CompositorContextId, Optional<u64> page_id, CompositorStateWebContentClient&, OwnedCanvasSurfaces, Function<void(Gfx::IntRect)> schedule_caret_repaint = {}, Function<void()> request_animation_frames = {});- ~ContextState();+ ContextState(Web::CompositorContextId, Optional<u64> page_id, WebContentClientId, CompositorCoreHost&, OwnedCanvasSurfaces);- bool is_owned_by(CompositorStateWebContentClient const&) const;- CompositorStateWebContentClient& web_content_client() const { return m_web_content_client; }+ bool is_owned_by(WebContentClientId) const;+ WebContentClientId web_content_client_id() const { return m_web_content_client_id; }void request_rendering_update();void dispatch_mouse_event_to_web_content(Web::MouseEvent const&, bool nested_context_scrolled_since_last_frame = false);void dispatch_key_event_to_web_content(Web::KeyEvent const&);@@ -280,6 +278,8 @@ public:void cancel_smooth_scroll(Web::AsyncScrollNodeStableID);Optional<Gfx::IntRect> advance_smooth_scroll_animations(MonotonicTime now);bool needs_animation_frames(MonotonicTime now) { return has_active_smooth_scroll_animations() || has_active_scroll_fling() || m_elastic_overscroll_controller.has_rebound() || visual_animations_need_frame(now) || m_scrollbar_controller.fades_need_frame(now); }+ void request_display_ticks_if_needed(MonotonicTime now);+ Optional<Gfx::IntRect> timer_fired(ContextTimer, MonotonicTime now);bool has_active_scroll_fling() const { return m_scroll_fling_controller.is_active(); }// The wheel event of the next step of the fling, which is scrolled by like a wheel event from the UI.@@ -318,6 +318,7 @@ public:void note_pointer_position(Optional<Gfx::FloatPoint>);Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates();bool has_pending_async_scroll_updates() const;+ void publish_pending_async_scroll_updates();Gfx::IntSize viewport_size() const { return m_viewport_size; }void viewport_size_updated(Gfx::IntSize);@@ -358,6 +359,20 @@ public:ScreenshotInputs frame_inputs_for_screenshot(MonotonicTime now);private:+ template<typename Message, typename... Arguments>+ void post_to_web_content(Arguments&&... arguments)+ {+ auto buffer = MUST(Message::static_encode(forward<Arguments>(arguments)...));+ m_host.post_message_to_web_content(m_web_content_client_id, buffer);+ }++ template<typename Message, typename... Arguments>+ void post_to_render_clock_of_web_content(Arguments&&... arguments)+ {+ auto buffer = MUST(Message::static_encode(forward<Arguments>(arguments)...));+ m_host.post_message_to_render_clock_of_web_content(m_web_content_client_id, buffer);+ }+struct ActiveSmoothScrollAnimation {Web::AsyncScrollNodeStableID stable_node_id;Compositing::AsyncScrollOperationID operation_id;@@ -471,10 +486,13 @@ private:void rebuild_wheel_hit_test_targets();FrameInputs frame_inputs_as_presented_now();Gfx::IntRect damage_rect_of_blinking_carets();+ void restart_caret_blink_for(Compositing::DisplayList const&, MonotonicTime now);+ void schedule_next_caret_blink(MonotonicTime now);void update_scrollbar_visibility(MonotonicTime now);void report_scrollbar_visibility_changes();- CompositorStateWebContentClient& m_web_content_client;+ CompositorCoreHost& m_host;+ WebContentClientId m_web_content_client_id;Web::CompositorContextId m_context_id;Optional<u64> m_page_id;@@ -507,7 +525,6 @@ private:KeyboardScrollController m_keyboard_scroll_controller;// The boxes that the keys held since none was have scrolled, whose gesture lasts until the last of them is released.Vector<Web::AsyncScrollNodeStableID> m_boxes_scrolled_by_held_keys;- RefPtr<Core::Timer> m_scroll_step_gesture_input_timer;WheelGestureRouting m_wheel_gesture_routing;Vector<ActiveSmoothScrollAnimation> m_smooth_scroll_animations;// The smooth scroll that a press beside the thumb of the captured scrollbar started.@@ -519,7 +536,7 @@ private:};Optional<ScrollbarPaging> m_scrollbar_paging;bool m_scrollbar_track_press_jumps { false };- RefPtr<Core::Timer> m_scrollbar_paging_timer;+ bool m_scrollbar_paging_timer_is_armed { false };PointerInNestedContexts m_pointer_in_nested_contexts;Optional<Gfx::FloatPoint> m_pointer_position;bool m_animated_content_was_under_pointer { false };@@ -530,9 +547,7 @@ private:Gfx::IntRect m_async_scrolling_viewport_rect;bool m_has_async_scrolling_state { false };- CaretBlinkTimer m_caret_blink_timer;- Function<void()> m_request_animation_frames;- RefPtr<Core::Timer> m_scrollbar_fade_out_timer;+ Optional<i64> m_caret_blink_cycle_start_time_ns;Web::InputTraceRecorder m_input_trace;Optional<u64> m_display_id;double m_display_refresh_rate { 60.0 };diff --git a/Tests/Compositor/CMakeLists.txt b/Tests/Compositor/CMakeLists.txtindex c3fce1e9f3f..195665c8a3c 100644--- a/Tests/Compositor/CMakeLists.txt+++ b/Tests/Compositor/CMakeLists.txt@@ -4,7 +4,6 @@ set(TEST_SOURCESTestAsyncScrollTree.cppTestBitmapExport.cppTestCanvasSurfaceRegistry.cpp- TestContextState.cppTestScrollbarController.cppTestVideoFrameHolds.cppTestVSyncScheduler.cppdiff --git a/Tests/Compositor/TestContextState.cpp b/Tests/Compositor/TestContextState.cppdeleted file mode 100644index 6ed832f0898..00000000000--- a/Tests/Compositor/TestContextState.cpp+++ /dev/null@@ -1,158 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <Compositor/CanvasSurfaceRegistry.h>-#include <Compositor/CompositorState.h>-#include <Compositor/ContextState.h>-#include <LibCompositing/DisplayList/DisplayList.h>-#include <LibCompositing/DisplayList/VisualContextTreeTestBuilder.h>-#include <LibCompositing/Scrolling/ScrollState.h>-#include <LibTest/TestCase.h>--class NullWebContentClient final : public Compositor::CompositorStateWebContentClient {-public:- virtual void dispatch_mouse_event_to_web_content(u64, Web::MouseEvent const&) override { }- virtual void dispatch_key_event_to_web_content(u64, Web::KeyEvent const&) override { }- virtual void dispatch_pinch_event_to_web_content(u64, Web::PinchEvent const&) override { }- virtual void request_rendering_update() override { }- virtual void rendering_opportunity(Web::CompositorContextId, i64, double) override { }- virtual void clock_tick(Web::CompositorContextId, i64, double, Vector<Web::CompositorScrollOffset> const&) override { }- virtual void async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates const&) override { }- virtual void create_video_edge(Media::VideoSinkHandle) override { }- virtual void release_video_edge(Media::VideoSinkHandle) override { }- virtual void placeholder_canvas_committed(Compositing::CanvasId, Gfx::IntSize, bool) override { }- virtual Compositing::CanvasSurfaceOwnerId canvas_surface_owner_id() const override { return Compositing::CanvasSurfaceOwnerId { 1 }; }-};--static Web::UniqueNodeID const document_id { 7 };--// A display list of a page whose viewport cannot be scrolled, so it records no scroll node.-static void install_display_list_without_scroll_nodes(Compositor::ContextState& context)-{- Compositing::VisualContextTreeTestBuilder builder;- auto visual_context_tree = builder.finish();- auto display_list = Compositing::DisplayList::create(visual_context_tree);- display_list->set_async_scrolling_metadata({ .document_id = document_id, .viewport_rect = { 0, 0, 800, 600 } });- context.install_display_list_update(display_list, move(visual_context_tree), {}, MonotonicTime::now());-}--static Web::PinchEvent pinch_event(double scale_delta)-{- Web::PinchEvent event;- event.position = { 400, 300 };- event.scale_delta = scale_delta;- return event;-}--TEST_CASE(pinch_zooms_a_page_without_scroll_nodes)-{- NullWebContentClient client;- Compositor::CanvasSurfaceRegistry canvas_surface_registry;- Compositor::ContextState context { Web::CompositorContextId { 1 }, 1, client, Compositor::OwnedCanvasSurfaces { canvas_surface_registry, client.canvas_surface_owner_id() } };- install_display_list_without_scroll_nodes(context);-- auto result = context.handle_pinch_event(pinch_event(1.0));- EXPECT(result.accepted);- EXPECT(result.frame_to_present.has_value());-}--TEST_CASE(pinch_zoom_of_a_page_without_scroll_nodes_survives_a_display_list_update)-{- NullWebContentClient client;- Compositor::CanvasSurfaceRegistry canvas_surface_registry;- Compositor::ContextState context { Web::CompositorContextId { 1 }, 1, client, Compositor::OwnedCanvasSurfaces { canvas_surface_registry, client.canvas_surface_owner_id() } };- install_display_list_without_scroll_nodes(context);-- // Zoom all the way in, then take a display list the main thread recorded before it saw the pinch.- EXPECT(context.handle_pinch_event(pinch_event(4.0)).accepted);- install_display_list_without_scroll_nodes(context);-- // The zoom is still at its maximum, so zooming in further has nothing to present.- auto result = context.handle_pinch_event(pinch_event(1.0));- EXPECT(result.accepted);- EXPECT(!result.frame_to_present.has_value());-}--TEST_CASE(pinch_zoom_is_reported_on_the_visual_viewport)-{- NullWebContentClient client;- Compositor::CanvasSurfaceRegistry canvas_surface_registry;- Compositor::ContextState context { Web::CompositorContextId { 1 }, 1, client, Compositor::OwnedCanvasSurfaces { canvas_surface_registry, client.canvas_surface_owner_id() } };- install_display_list_without_scroll_nodes(context);-- // Zooming in 2x around the middle of the viewport moves the visual viewport to the middle of the page.- EXPECT(context.handle_pinch_event(pinch_event(1.0)).accepted);- auto updates = context.take_pending_async_scroll_updates();- EXPECT_EQ(updates.scroll_offsets.size(), 1u);- auto const& scroll_offset = updates.scroll_offsets.first();- EXPECT_EQ(scroll_offset.stable_node_id.node_id, document_id);- EXPECT(scroll_offset.stable_node_id.kind == Web::AsyncScrollNodeKind::VisualViewport);- EXPECT_EQ(scroll_offset.visual_viewport_scale, 2.0f);- EXPECT_EQ(scroll_offset.compositor_scroll_offset, Gfx::FloatPoint(200, 150));- EXPECT_EQ(scroll_offset.unadopted_scroll_delta, Gfx::FloatPoint(200, 150));-}--TEST_CASE(pinch_zoom_is_presented_until_the_main_thread_asks_for_another)-{- NullWebContentClient client;- Compositor::CanvasSurfaceRegistry canvas_surface_registry;- Compositor::ContextState context { Web::CompositorContextId { 1 }, 1, client, Compositor::OwnedCanvasSurfaces { canvas_surface_registry, client.canvas_surface_owner_id() } };- install_display_list_without_scroll_nodes(context);-- // A display list the main thread recorded without the zoom keeps it at its maximum.- EXPECT(context.handle_pinch_event(pinch_event(4.0)).accepted);- install_display_list_without_scroll_nodes(context);- auto result_at_maximum = context.handle_pinch_event(pinch_event(1.0));- EXPECT(result_at_maximum.accepted);- EXPECT(!result_at_maximum.frame_to_present.has_value());-- // A request of the main thread's own, such as resetting the zoom, is what moves the visual viewport from there.- Compositing::ScrollRequest reset_zoom {- .stable_node_id = { .node_id = document_id, .kind = Web::AsyncScrollNodeKind::VisualViewport },- .request_id = 1,- .jump_offset = Gfx::FloatPoint {},- .visual_viewport_scale = 1.0f,- .relative_scroll = {},- .relative_scroll_moves_visual_viewport_first = false,- .instant_scroll_is_for_user_input = false,- .smooth_scroll = {},- .takes_over_from_momentum = false,- };- (void)context.apply_scroll_requests({ &reset_zoom, 1 }, MonotonicTime::now());- EXPECT(context.handle_pinch_event(pinch_event(1.0)).frame_to_present.has_value());-}--TEST_CASE(wheel_pans_the_zoomed_visual_viewport_of_a_page_without_scroll_nodes)-{- NullWebContentClient client;- Compositor::CanvasSurfaceRegistry canvas_surface_registry;- Compositor::ContextState context { Web::CompositorContextId { 1 }, 1, client, Compositor::OwnedCanvasSurfaces { canvas_surface_registry, client.canvas_surface_owner_id() } };- install_display_list_without_scroll_nodes(context);-- Web::MouseEvent wheel_event;- wheel_event.type = Web::MouseEvent::Type::MouseWheel;- wheel_event.position = { 400, 300 };- wheel_event.wheel_delta_y = 50;- wheel_event.wheel_delta_precision = Web::WheelDeltaPrecision::Precise;-- // Before the page is zoomed in, there is nothing for the wheel to pan.- EXPECT(!context.handle_wheel_event(wheel_event, false, {}, MonotonicTime::now()).accepted);-- EXPECT(context.handle_pinch_event(pinch_event(1.0)).accepted);- (void)context.take_pending_async_scroll_updates();- auto result = context.handle_wheel_event(wheel_event, false, {}, MonotonicTime::now());- EXPECT(result.accepted);- EXPECT(result.frame_to_present.has_value());-- // The main thread adopts the pan as a scroll of the document's visual viewport, at half the delta at 2x zoom.- auto updates = context.take_pending_async_scroll_updates();- EXPECT_EQ(updates.document_id, document_id);- EXPECT_EQ(updates.scroll_offsets.size(), 1u);- auto const& scroll_offset = updates.scroll_offsets.first();- EXPECT_EQ(scroll_offset.stable_node_id.node_id, document_id);- EXPECT_EQ(scroll_offset.stable_node_id.kind, Web::AsyncScrollNodeKind::VisualViewport);- EXPECT_EQ(scroll_offset.unadopted_scroll_delta, Gfx::FloatPoint(0, 25));-}