Truly independent web browser
LibWeb+LibCompositing: Remove the WebContent model of wheel routing
Aliaksandr Kalenik293804a2a275
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cppindex 3fa8d92a0f1..2836a468f92 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp@@ -6,9 +6,7 @@#include <AK/JsonArray.h>#include <AK/JsonObject.h>-#include <AK/Utf16View.h>#include <LibCompositing/DisplayList/DisplayList.h>-#include <LibCompositing/Scrolling/AsyncScrollTree.h>#include <LibCompositing/Scrolling/AsyncScrollingState.h>#include <LibCompositing/Scrolling/ScrollState.h>@@ -339,70 +337,4 @@ WheelRoutingAdmission wheel_routing_admission_for(AsyncScrollingState const& stareturn wheel_routing_admission_for(state);}-Utf16View wheel_routing_admission_to_utf16_view(WheelRoutingAdmission admission)-{- switch (admission) {- case WheelRoutingAdmission::Accepted:- return u"accepted"sv;- case WheelRoutingAdmission::NoAsyncScrollingState:- return u"no async scrolling state"sv;- case WheelRoutingAdmission::BlockingWheelEventListeners:- return u"blocking wheel event listeners"sv;- case WheelRoutingAdmission::NoScrollNode:- return u"no scroll node"sv;- case WheelRoutingAdmission::StaleWheelEventListeners:- return u"stale wheel event listeners"sv;- }- VERIFY_NOT_REACHED();-}--static AsyncScrollTree scroll_tree_for_hit_testing(AsyncScrollingState async_scrolling_state, RefPtr<Compositing::DisplayList const> const& display_list, Compositing::AccumulatedVisualContextTree const* visual_context_tree, Compositing::ScrollStateSnapshot const& scroll_state_snapshot)-{- AsyncScrollTree scroll_tree;- scroll_tree.set_state(move(async_scrolling_state));- scroll_tree.rebuild_wheel_hit_test_targets(display_list, visual_context_tree, scroll_state_snapshot);- return scroll_tree;-}--bool blocks_wheel_event_at_position(AsyncScrollingState const& async_scrolling_state, RefPtr<Compositing::DisplayList const> const& display_list, Compositing::AccumulatedVisualContextTree const* visual_context_tree, Compositing::ScrollStateSnapshot const& scroll_state_snapshot, Gfx::FloatPoint position)-{- if (async_scrolling_state.has_blocking_wheel_event_region_covering_viewport)- return true;-- // If a caller knows blocking wheel listeners exist but cannot provide a display list for visual-context hit- // testing, async scrolling must fail closed. Sending the input to the main thread is slower, but it preserves- // cancelability.- if (!display_list || !visual_context_tree)- return async_scrolling_state.has_blocking_wheel_event_listeners;-- auto scroll_tree = scroll_tree_for_hit_testing(async_scrolling_state, display_list, visual_context_tree, scroll_state_snapshot);- return scroll_tree.blocks_wheel_event_at_position(*visual_context_tree, position);-}--WheelScrollAdmission admit_wheel_scroll(AsyncScrollingState const& async_scrolling_state, RefPtr<Compositing::DisplayList const> const& display_list, Compositing::AccumulatedVisualContextTree const* visual_context_tree, Compositing::ScrollStateSnapshot const& scroll_state_snapshot, Gfx::FloatPoint position, Gfx::FloatPoint delta, bool blocking_wheel_event_regions_are_current)-{- WheelHitTestResult hit_test_result;- if (display_list && visual_context_tree) {- auto scroll_tree = scroll_tree_for_hit_testing(async_scrolling_state, display_list, visual_context_tree, scroll_state_snapshot);- hit_test_result = scroll_tree.hit_test_scroll_node_for_wheel(*visual_context_tree, position, delta);- } else if (async_scrolling_state.has_blocking_wheel_event_listeners) {- hit_test_result.outcome = WheelHitTestOutcome::BlockedByWheelEventRegion;- }- if (hit_test_result.outcome == WheelHitTestOutcome::BlockedByMainThreadRegion)- return WheelScrollAdmission::BlockedByMainThreadRegion;-- // Async scrolling may only start when the snapshot can prove that the wheel event cannot be canceled by script- // at this position. Stale or missing blocker information sends the event back to the main thread.- if (async_scrolling_state.has_blocking_wheel_event_listeners) {- if (!blocking_wheel_event_regions_are_current)- return WheelScrollAdmission::StaleBlockingWheelEventRegions;- if (hit_test_result.outcome == WheelHitTestOutcome::BlockedByWheelEventRegion)- return WheelScrollAdmission::BlockedByWheelEventRegion;- }-- if (!hit_test_result.node_id.has_value())- return WheelScrollAdmission::NoScrollableTarget;- return WheelScrollAdmission::Accepted;-}-}diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.hindex 2414e4e92ef..9c93d2d6915 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h@@ -172,14 +172,6 @@ enum class WheelRoutingAdmission {StaleWheelEventListeners,};-enum class WheelScrollAdmission {- Accepted,- NoScrollableTarget,- BlockedByMainThreadRegion,- StaleBlockingWheelEventRegions,- BlockedByWheelEventRegion,-};-COMPOSITING_API AsyncScrollingState async_scrolling_state_from_display_list(Compositing::DisplayList const&);// The scrolling state as tests read it, from WebContent and from the compositor alike.COMPOSITING_API JsonObject async_scrolling_state_to_json(AsyncScrollingState const&);@@ -187,10 +179,7 @@ COMPOSITING_API WheelRoutingAdmission wheel_routing_admission_for(AsyncScrolling// The admission of a scrolling state recorded before the newest change to the page's blocking wheel event listeners is// stale, as the state may not have the regions that change made.COMPOSITING_API WheelRoutingAdmission wheel_routing_admission_for(AsyncScrollingState const&, u64 newest_wheel_event_listener_state_generation);-COMPOSITING_API Utf16View wheel_routing_admission_to_utf16_view(WheelRoutingAdmission);// Why a wheel step that the admission does not let the compositor scroll is left to the main thread.COMPOSITING_API Web::InputRoutingDecision input_routing_decision_for_wheel_step_not_admitted_by(WheelRoutingAdmission);-COMPOSITING_API bool blocks_wheel_event_at_position(AsyncScrollingState const&, RefPtr<Compositing::DisplayList const> const&, Compositing::AccumulatedVisualContextTree const*, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position);-COMPOSITING_API WheelScrollAdmission admit_wheel_scroll(AsyncScrollingState const&, RefPtr<Compositing::DisplayList const> const&, Compositing::AccumulatedVisualContextTree const*, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position, Gfx::FloatPoint delta, bool blocking_wheel_event_regions_are_current);}diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex ec605b9cffa..9ca5d8dfc2f 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -2651,120 +2651,6 @@ WebIDL::ExceptionOr<GC::Ref<JS::Object>> Internals::image_animation_state_for_urreturn object;}-struct AsyncScrollingStateSnapshot {- Compositing::AsyncScrollingState state;- RefPtr<Compositing::DisplayList const> display_list;- Compositing::AccumulatedVisualContextTree visual_context_tree;- GC::Root<DOM::Document> document;-};--static Optional<AsyncScrollingStateSnapshot> capture_async_scrolling_state(DOM::Document& document)-{- Layout::ForcedReadScope read { document };- document.update_layout(DOM::UpdateLayoutReason::InternalsHitTest);- auto navigable = document.navigable();- if (!navigable || !document.has_committed_viewport_box())- return {};- auto display_list = document.record_display_list(read, HTML::PaintConfig {}, navigable->display_list_resource_storage(), Painting::PaintCommandCacheMode::ReadWrite);- if (!display_list)- return {};- return AsyncScrollingStateSnapshot {- .state = Compositing::async_scrolling_state_from_display_list(*display_list),- .display_list = display_list,- .visual_context_tree = document.paint_state().visual_context_tree(document),- .document = GC::make_root(document),- };-}--Compositing::AsyncScrollingState Internals::async_scrolling_state()-{- auto snapshot = capture_async_scrolling_state(window().associated_document());- if (!snapshot.has_value())- return {};- return move(snapshot->state);-}--bool Internals::async_scrolling_state_blocks_wheel_event_at(double x, double y)-{- auto snapshot = capture_async_scrolling_state(window().associated_document());- if (!snapshot.has_value())- return false;- return Compositing::blocks_wheel_event_at_position(snapshot->state, snapshot->display_list, &snapshot->visual_context_tree, snapshot->document->scroll_state_snapshot(), { static_cast<float>(x), static_cast<float>(y) });-}--Utf16String Internals::async_scrolling_state_wheel_routing_admission()-{- auto snapshot = capture_async_scrolling_state(window().associated_document());- auto admission = snapshot.has_value() ? Compositing::wheel_routing_admission_for(snapshot->state) : Compositing::WheelRoutingAdmission::NoAsyncScrollingState;- return Utf16String::from_utf16(Compositing::wheel_routing_admission_to_utf16_view(admission));-}--static Compositing::WheelScrollAdmission wheel_scroll_admission_at(DOM::Document& document, double x, double y, double delta_x, double delta_y, bool force_stale_wheel_event_regions)-{- auto snapshot = capture_async_scrolling_state(document);- if (!snapshot.has_value())- return Compositing::WheelScrollAdmission::NoScrollableTarget;- return Compositing::admit_wheel_scroll(- snapshot->state,- snapshot->display_list,- &snapshot->visual_context_tree,- snapshot->document->scroll_state_snapshot(),- { static_cast<float>(x), static_cast<float>(y) },- { static_cast<float>(delta_x), static_cast<float>(delta_y) },- snapshot->state.has_blocking_wheel_event_listeners && !force_stale_wheel_event_regions);-}--bool Internals::async_scrolling_state_can_wheel_scroll_at(double x, double y, double delta_x, double delta_y, bool force_stale_wheel_event_regions)-{- return wheel_scroll_admission_at(window().associated_document(), x, y, delta_x, delta_y, force_stale_wheel_event_regions) == Compositing::WheelScrollAdmission::Accepted;-}--static Utf16String wheel_scroll_admission_to_string(Compositing::WheelScrollAdmission admission)-{- switch (admission) {- case Compositing::WheelScrollAdmission::Accepted:- return "accepted"_utf16;- case Compositing::WheelScrollAdmission::NoScrollableTarget:- return "no-scrollable-target"_utf16;- case Compositing::WheelScrollAdmission::BlockedByMainThreadRegion:- return "blocked-by-main-thread-region"_utf16;- case Compositing::WheelScrollAdmission::StaleBlockingWheelEventRegions:- return "stale-blocking-wheel-event-regions"_utf16;- case Compositing::WheelScrollAdmission::BlockedByWheelEventRegion:- return "blocked-by-wheel-event-region"_utf16;- }- VERIFY_NOT_REACHED();-}--Utf16String Internals::async_scrolling_state_wheel_scroll_admission_at(double x, double y, double delta_x, double delta_y, bool force_stale_wheel_event_regions)-{- auto admission = wheel_scroll_admission_at(window().associated_document(), x, y, delta_x, delta_y, force_stale_wheel_event_regions);- return wheel_scroll_admission_to_string(admission);-}--Utf16String Internals::async_scrolling_state_wheel_target_at(double x, double y, double delta_x, double delta_y)-{- auto snapshot = capture_async_scrolling_state(window().associated_document());- if (!snapshot.has_value())- return "none"_utf16;-- Compositing::AsyncScrollTree scroll_tree;- scroll_tree.set_state(move(snapshot->state));- scroll_tree.rebuild_wheel_hit_test_targets(snapshot->display_list, &snapshot->visual_context_tree, snapshot->document->scroll_state_snapshot());-- auto target = scroll_tree.hit_test_scroll_node_for_wheel(- snapshot->visual_context_tree,- { static_cast<float>(x), static_cast<float>(y) },- { static_cast<float>(delta_x), static_cast<float>(delta_y) });- if (target.outcome == Compositing::WheelHitTestOutcome::BlockedByMainThreadRegion)- return "main-thread"_utf16;- if (!target.node_id.has_value())- return "none"_utf16;- if (scroll_tree.scroll_node_is_viewport(*target.node_id))- return "viewport"_utf16;- return "non-viewport"_utf16;-}-String Internals::viewport_overflow_x(){auto& document = window().associated_document();@@ -3022,11 +2908,6 @@ GC::Ref<JS::Object> Internals::style_invalidation_counters_object() constreturn object;}-GC::Ref<JS::Object> Internals::async_scrolling_state_object()-{- return scrolling_state_report_to_object(window(), Compositing::async_scrolling_state_to_json(async_scrolling_state()));-}-GC::Ref<JS::Object> Internals::recorded_async_scrolling_state_object(){auto* display_list = window().associated_document().paint_state().display_list_used_as_paint_command_cache_source();diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.hindex 279ab9c8291..e7851e7e4f1 100644--- a/Libraries/LibWeb/Internals/Internals.h+++ b/Libraries/LibWeb/Internals/Internals.h@@ -305,13 +305,6 @@ public:void disconnect_media_server();void set_page_muted(bool muted);WebIDL::UnsignedLongLong active_image_style_value_animation_count();- Compositing::AsyncScrollingState async_scrolling_state();- GC::Ref<JS::Object> async_scrolling_state_object();- bool async_scrolling_state_blocks_wheel_event_at(double x, double y);- bool async_scrolling_state_can_wheel_scroll_at(double x, double y, double delta_x, double delta_y, bool force_stale_wheel_event_regions);- Utf16String async_scrolling_state_wheel_routing_admission();- Utf16String async_scrolling_state_wheel_scroll_admission_at(double x, double y, double delta_x, double delta_y, bool force_stale_wheel_event_regions);- Utf16String async_scrolling_state_wheel_target_at(double x, double y, double delta_x, double delta_y);String viewport_overflow_x();private:diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idlindex fd28a36c423..1b78fa45830 100644--- a/Libraries/LibWeb/Internals/Internals.idl+++ b/Libraries/LibWeb/Internals/Internals.idl@@ -370,12 +370,6 @@ interface Internals {undefined disconnectMediaServer();undefined setPageMuted(boolean muted);- [ImplementedAs=async_scrolling_state_object] object asyncScrollingState();- boolean asyncScrollingStateBlocksWheelEventAt(double x, double y);- boolean asyncScrollingStateCanWheelScrollAt(double x, double y, double deltaX, double deltaY, optional boolean forceStaleWheelEventRegions = false);- DOMString asyncScrollingStateWheelRoutingAdmission();- DOMString asyncScrollingStateWheelScrollAdmissionAt(double x, double y, double deltaX, double deltaY, optional boolean forceStaleWheelEventRegions = false);- DOMString asyncScrollingStateWheelTargetAt(double x, double y, double deltaX, double deltaY);DOMString viewportOverflowX();};diff --git a/Tests/Compositor/TestAsyncScrollTree.cpp b/Tests/Compositor/TestAsyncScrollTree.cppindex 5811e95368f..33da9446d05 100644--- a/Tests/Compositor/TestAsyncScrollTree.cpp+++ b/Tests/Compositor/TestAsyncScrollTree.cpp@@ -100,19 +100,16 @@ TEST_CASE(blocking_wheel_event_hit_testing_fails_closed_for_invalid_visual_conte});auto display_list = make_empty_display_list(visual_context_tree);- EXPECT(Compositing::blocks_wheel_event_at_position(state, display_list, &visual_context_tree, {}, { 200, 200 }));- EXPECT_EQ(Compositing::admit_wheel_scroll(state, display_list, &visual_context_tree, {}, { 200, 200 }, { 0, 10 }, true),- Compositing::WheelScrollAdmission::BlockedByWheelEventRegion);-Compositing::AsyncScrollTree scroll_tree;scroll_tree.set_state(move(state));scroll_tree.rebuild_wheel_hit_test_targets(display_list, &visual_context_tree, {});+ EXPECT(scroll_tree.blocks_wheel_event_at_position(visual_context_tree, { 200, 200 }));auto result = scroll_tree.hit_test_scroll_node_for_wheel(visual_context_tree, { 200, 200 }, { 0, 10 });EXPECT_EQ(result.outcome, Compositing::WheelHitTestOutcome::BlockedByWheelEventRegion);EXPECT(!result.node_id.has_value());}-TEST_CASE(wheel_scroll_admission_preserves_main_thread_region_and_viewport_blocker_precedence)+TEST_CASE(first_wheel_step_route_puts_main_thread_region_before_blocking_region_and_viewport_blocker_before_both){auto visual_context_tree = make_visual_context_tree();auto display_list = make_empty_display_list(visual_context_tree);@@ -126,16 +123,18 @@ TEST_CASE(wheel_scroll_admission_preserves_main_thread_region_and_viewport_block.context = { Compositing::VISUAL_VIEWPORT_NODE_INDEX },.rect = { 0, 0, 100, 100 },});+ auto route_first_wheel_step_at = [&](Compositing::AsyncScrollingState state) {+ Compositing::AsyncScrollTree scroll_tree;+ scroll_tree.set_state(move(state));+ scroll_tree.rebuild_wheel_hit_test_targets(display_list, &visual_context_tree, {});+ EXPECT(scroll_tree.blocks_wheel_event_at_position(visual_context_tree, { 20, 20 }));+ return scroll_tree.route_first_wheel_step(Compositing::WheelRoutingAdmission::Accepted, visual_context_tree, { 20, 20 }, { 0, 10 }).decision;+ };- EXPECT(Compositing::blocks_wheel_event_at_position(state, display_list, &visual_context_tree, {}, { 20, 20 }));- EXPECT_EQ(Compositing::admit_wheel_scroll(state, display_list, &visual_context_tree, {}, { 20, 20 }, { 0, 10 }, true),- Compositing::WheelScrollAdmission::BlockedByMainThreadRegion);- EXPECT_EQ(Compositing::admit_wheel_scroll(state, display_list, &visual_context_tree, {}, { 20, 20 }, { 0, 10 }, false),- Compositing::WheelScrollAdmission::BlockedByMainThreadRegion);+ EXPECT_EQ(route_first_wheel_step_at(state), Web::InputRoutingDecision::BlockedByMainThreadRegion);state.has_blocking_wheel_event_region_covering_viewport = true;- EXPECT_EQ(Compositing::admit_wheel_scroll(state, display_list, &visual_context_tree, {}, { 20, 20 }, { 0, 10 }, true),- Compositing::WheelScrollAdmission::BlockedByWheelEventRegion);+ EXPECT_EQ(route_first_wheel_step_at(state), Web::InputRoutingDecision::BlockedByWheelEventRegion);}TEST_CASE(async_scrolling_resolves_sticky_offsets_from_the_visual_context_tree)