Truly independent web browser
LibWeb+Compositor: Hand mouse input to the scrollbars of nested contexts
Aliaksandr Kalenikc6efe979dbc5
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cppindex b26a85f2747..740e1460851 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp@@ -469,20 +469,51 @@ Optional<AsyncScrollTree::NestedContextWheelRegionHit> AsyncScrollTree::topmost_return {};}-Optional<NestedContextWheelHit> AsyncScrollTree::nested_context_for_wheel_at(Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position) const+static NestedContextHit nested_context_hit_in_region(NestedContextWheelRegion const& region, Gfx::FloatPoint position_in_context)+{+ return NestedContextHit {+ .child_context_id = region.child_context_id,+ .position_in_content_box = position_in_context - region.rect.location(),+ .content_box_size = region.rect.size(),+ .paint_order_index = region.paint_order_index,+ };+}++Optional<NestedContextHit> AsyncScrollTree::nested_context_at(Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position) const{if (m_visual_context_tree_structural_epoch != visual_context_tree.structural_epoch())return {};- if (main_thread_wheel_event_region_contains(visual_context_tree, position))- return {};auto hit = topmost_nested_context_wheel_region_at(visual_context_tree, position);if (!hit.has_value() || is_covered_by_hit_test_target_painted_after(hit->region.paint_order_index, visual_context_tree, position))return {};- return NestedContextWheelHit {- .child_context_id = hit->region.child_context_id,- .position_in_content_box = hit->position_in_context - hit->region.rect.location(),- .content_box_size = hit->region.rect.size(),- };+ return nested_context_hit_in_region(hit->region, hit->position_in_context);+}++Optional<NestedContextHit> AsyncScrollTree::nested_context_for_wheel_at(Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position) const+{+ if (m_visual_context_tree_structural_epoch != visual_context_tree.structural_epoch())+ return {};+ if (main_thread_wheel_event_region_contains(visual_context_tree, position))+ return {};+ return nested_context_at(visual_context_tree, position);+}++Optional<NestedContextHit> AsyncScrollTree::position_in_content_of_nested_context(Web::CompositorContextId child_context_id, Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position) const+{+ if (m_visual_context_tree_structural_epoch != visual_context_tree.structural_epoch())+ return {};+ for (auto const& cached_region : m_cached_nested_context_wheel_regions.in_reverse()) {+ auto const& region = cached_region.region;+ if (region.child_context_id != child_context_id)+ continue;+ if (!visual_context_tree.context_is_valid(region.context))+ return {};+ auto position_in_context = visual_context_tree.transform_point_for_hit_test(region.context, position, m_scroll_state_snapshot, Compositing::AccumulatedVisualContextTree::ClipBehavior::Ignore);+ if (!position_in_context.has_value())+ return {};+ return nested_context_hit_in_region(region, *position_in_context);+ }+ return {};}WheelHitTestResult AsyncScrollTree::hit_test_scroll_node_for_wheel(Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position, Gfx::FloatPoint delta, Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> const& in_flight_destination_for, WheelStepDispatch wheel_step_dispatch, NestedContextRegions nested_context_regions) constdiff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.hindex bd41cb95be5..d886d7c0a84 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h@@ -73,12 +73,15 @@ enum class NestedContextRegions : u8 {Ignore,};-// Where a wheel over the content of a nested context lands in it.-struct NestedContextWheelHit {+// Where a wheel or the pointer over the content of a nested context lands in it.+struct NestedContextHit {Web::CompositorContextId child_context_id;// Relative to the origin of the nested context's content box, in the device pixels of the containing context.Gfx::FloatPoint position_in_content_box;Gfx::FloatSize content_box_size;+ // Where the nested context's content is painted among the other things in the containing context that take+ // pointer input.+ u32 paint_order_index { 0 };};struct WheelScrollTarget {@@ -149,7 +152,13 @@ public:bool blocks_wheel_event_at_position(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;WheelHitTestResult hit_test_scroll_node_for_wheel(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position, Gfx::FloatPoint delta, Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> const& in_flight_destination_for = {}, WheelStepDispatch = WheelStepDispatch::NotYetDispatched, NestedContextRegions = NestedContextRegions::LeaveToMainThread) const;// The nested context whose content is the topmost thing taking pointer input at the position, if any.- Optional<NestedContextWheelHit> nested_context_for_wheel_at(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;+ Optional<NestedContextHit> nested_context_at(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;+ // As above, unless the main thread takes the wheel events at the position.+ Optional<NestedContextHit> nested_context_for_wheel_at(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;+ // Where the position lands in the content of the nested context, even outside of that content and its clips, as+ // the pointer of a drag that began in there moves on.+ Optional<NestedContextHit> position_in_content_of_nested_context(Web::CompositorContextId, Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;+ bool has_nested_contexts() const { return !m_nested_context_wheel_regions.is_empty(); }bool has_wheel_hit_test_targets_for(Compositing::AccumulatedVisualContextTree const& visual_context_tree) const { return m_visual_context_tree_structural_epoch == visual_context_tree.structural_epoch(); }// Whether something painted above the given place in paint order takes pointer input at the position. It is taken// to be covered whenever that cannot be told.diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cppindex a550eef591c..e402666ea82 100644--- a/Libraries/LibWeb/Page/EventHandler.cpp+++ b/Libraries/LibWeb/Page/EventHandler.cpp@@ -389,8 +389,13 @@ EventResult EventHandler::handle_mousedown(CSSPixelPoint visual_viewport_positioif (!node)return EventResult::Dropped;- // The compositor already scrolls for this press, so its scrollbar takes it whatever is hit here by now.- if (scrollbar_dragged_by_compositor.has_value()) {+ // The compositor already scrolls for this press, so its scrollbar takes it whatever is hit here by now. A scrollbar+ // of a document nested in this one takes it there, and only the process that owns that document's context can tell+ // which scroller the compositor names.+ auto scrollbar_is_in_this_document = scrollbar_dragged_by_compositor.has_value()+ && m_navigable->has_compositor_context()+ && m_navigable->compositor_context().id() == scrollbar_dragged_by_compositor->context_id;+ if (scrollbar_is_in_this_document) {auto scrollbar = m_navigable->scrollbar_dragged_by_compositor(read, *scrollbar_dragged_by_compositor);if (!scrollbar)return EventResult::Dropped;@@ -406,12 +411,14 @@ EventResult EventHandler::handle_mousedown(CSSPixelPoint visual_viewport_positiom_mousedown_click_count = click_count;- if (!scrollbar_dragged_by_compositor.has_value() && !next_pointer_event_is_captured()) {+ if (!scrollbar_is_in_this_document && (scrollbar_dragged_by_compositor.has_value() || !next_pointer_event_is_captured())) {auto dispath_result = dispatch_event_to_nested_navigable(*this, *target_layout_node, node, visual_viewport_position, remote_target, [=](EventHandler& event_handler, CSSPixelPoint position) -> EventResult {- return event_handler.handle_mousedown(position, screen_position, button, buttons, modifiers, click_count, {}, remote_target);+ return event_handler.handle_mousedown(position, screen_position, button, buttons, modifiers, click_count, scrollbar_dragged_by_compositor, remote_target);});if (dispath_result.has_value())return *dispath_result;+ if (scrollbar_dragged_by_compositor.has_value())+ return EventResult::Dropped;}m_navigable->page().set_focused_navigable(m_navigable);diff --git a/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.cpp b/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.cppindex f6da8be8c52..0740180b6ac 100644--- a/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.cpp+++ b/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.cpp@@ -49,6 +49,7 @@ ErrorOr<Web::CompositorScrollOffset> decode(Decoder& decoder)template<>ErrorOr<void> encode(Encoder& encoder, Web::ScrollbarDraggedByCompositor const& scrollbar){+ TRY(encoder.encode(scrollbar.context_id));TRY(encoder.encode(scrollbar.scroller_stable_node_id));TRY(encoder.encode(scrollbar.vertical));return {};@@ -58,6 +59,7 @@ template<>ErrorOr<Web::ScrollbarDraggedByCompositor> decode(Decoder& decoder){return Web::ScrollbarDraggedByCompositor {+ .context_id = TRY(decoder.decode<Web::CompositorContextId>()),.scroller_stable_node_id = TRY(decoder.decode<Web::AsyncScrollNodeStableID>()),.vertical = TRY(decoder.decode<bool>()),};diff --git a/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.h b/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.hindex 12e06f4378d..d7a339b50cd 100644--- a/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.h+++ b/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.h@@ -12,6 +12,7 @@#include <LibIPC/Forward.h>#include <LibWebCommon/Export.h>#include <LibWebCommon/Forward.h>+#include <LibWebCommon/Page/CompositorContextId.h>#include <LibWebCommon/PixelUnits.h>namespace Web {@@ -43,6 +44,9 @@ struct CompositorScrollOffset {// The compositor drags the thumb of a scrollbar the display list paints, while the mouse events of that drag still// reach the main thread so that everything but the scrolling stays there.struct ScrollbarDraggedByCompositor {+ // The context of the document the scroller is in, which may be nested in the one the event is dispatched to. Only+ // the process that owns that context can tell which node the scroller's id names.+ CompositorContextId context_id;AsyncScrollNodeStableID scroller_stable_node_id;bool vertical { false };diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 08abca7fa2b..7c9c42ac411 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -669,7 +669,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId cif (is_wheel_event)result = scroll_for_wheel_step(context_id, *context, event, WheelStepOrigin::UI);else- result = context->handle_mouse_event(event);+ result = handle_mouse_event_in_nested_contexts(context_id, *context, event);if (result.nested_context_hand_off.has_value())record_routing(*result.nested_context_hand_off);if (result.routing_decision.has_value()) {@@ -678,7 +678,8 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c}// Schedules the present, publishes the scroll updates the event produced and asks for a rendering update, all of- // which reach WebContent ahead of the event itself on the same connection.+ // which reach WebContent ahead of the event itself on the same connection. Those of a nested context another+ // process owns go on that process's connection instead, while the event reaches it through the UI.auto handled = apply_context_update_result(context_id, *context, result);// A wheel event that lets go of a stretched scroller presents nothing itself; the rebound does from here on. A press// beside the thumb of a scrollbar scrolls there in an animation too.@@ -698,6 +699,203 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId ccontext->dispatch_mouse_event_to_web_content(event, nested_context_scrolled_since_last_frame(context_id));}+// The content box of a nested context is drawn scaled to the size of its viewport.+static Optional<Gfx::FloatPoint> position_in_nested_context(Compositing::NestedContextHit const& hit, ContextState const& nested_context)+{+ auto viewport_size = nested_context.presenter().viewport_size().to_type<float>();+ if (hit.content_box_size.is_empty() || viewport_size.is_empty())+ return {};+ return Gfx::FloatPoint {+ hit.position_in_content_box.x() * viewport_size.width() / hit.content_box_size.width(),+ hit.position_in_content_box.y() * viewport_size.height() / hit.content_box_size.height(),+ };+}++ContextState* CompositorState::context_still_nested_in(Web::CompositorContextId containing_context_id, Optional<Web::CompositorContextId> context_id)+{+ if (!context_id.has_value())+ return nullptr;+ auto* context = context_if_present(*context_id);+ if (!context || !is_nested_in(containing_context_id, *context))+ return nullptr;+ return context;+}++Optional<Gfx::FloatPoint> CompositorState::position_in_nested_context_ignoring_clips(Web::CompositorContextId presenting_context_id, ContextState& presenting_context, ContextState& nested_context, Gfx::FloatPoint position)+{+ Vector<ContextState*, 4> contexts_from_nested_context_outward;+ auto* context = &nested_context;+ // A walk up the parents that outlasts the number of contexts went around a loop.+ for (size_t remaining_contexts = m_contexts.size(); context != &presenting_context; --remaining_contexts) {+ if (remaining_contexts == 0)+ return {};+ contexts_from_nested_context_outward.append(context);+ auto parent_context_id = context->parent_context_id();+ if (!parent_context_id.has_value())+ return {};+ context = *parent_context_id == presenting_context_id ? &presenting_context : context_if_present(*parent_context_id);+ if (!context)+ return {};+ }++ auto* containing_context = &presenting_context;+ for (auto* context_in_between : contexts_from_nested_context_outward.in_reverse()) {+ auto hit = containing_context->position_in_content_of_nested_context(context_in_between->context_id(), position);+ if (!hit.has_value())+ return {};+ auto position_in_context = position_in_nested_context(*hit, *context_in_between);+ if (!position_in_context.has_value())+ return {};+ position = *position_in_context;+ containing_context = context_in_between;+ }+ return position;+}++ContextState::ContextUpdateResult CompositorState::handle_mouse_event_in_nested_contexts(Web::CompositorContextId context_id, ContextState& context, Web::MouseEvent const& event)+{+ using Type = Web::MouseEvent::Type;+ auto& pointer = context.pointer_in_nested_contexts();++ auto* context_with_captured_scrollbar = context_still_nested_in(context_id, pointer.context_with_captured_scrollbar);+ if (!context_with_captured_scrollbar || !context_with_captured_scrollbar->has_captured_scrollbar()) {+ pointer.context_with_captured_scrollbar.clear();+ context_with_captured_scrollbar = nullptr;+ }++ // The nested context presents and publishes what the event changed, and this context reports how the event went.+ auto result_of_nested_context = [&](Web::CompositorContextId nested_context_id, ContextState& nested_context, ContextState::ContextUpdateResult const& nested_result, Optional<PendingFrame> frame_of_this_context) {+ 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());+ return ContextState::ContextUpdateResult {+ .accepted = nested_result.accepted,+ .frame_to_present = move(frame_of_this_context),+ .scrollbar_dragged_by_compositor = nested_result.scrollbar_dragged_by_compositor,+ .routing_decision = nested_result.routing_decision,+ .routed_scroller = ids_are_of_this_process ? nested_result.routed_scroller : Optional<Web::AsyncScrollNodeStableID> {},+ .nested_context_hand_off = Web::InputRoutingDecision::HandedToNestedContext,+ };+ };++ auto send_to_context_with_captured_scrollbar = [&](Web::MouseEvent const& event_to_send) {+ auto nested_context_id = *pointer.context_with_captured_scrollbar;+ auto position = Gfx::FloatPoint {+ static_cast<float>(event_to_send.position.x().value()),+ static_cast<float>(event_to_send.position.y().value()),+ };+ // A leave or a cancel has no position of its own.+ if (first_is_one_of(event_to_send.type, Type::MouseDown, Type::MouseMove, Type::MouseUp)) {+ if (auto position_in_nested_context = position_in_nested_context_ignoring_clips(context_id, context, *context_with_captured_scrollbar, position); position_in_nested_context.has_value())+ pointer.last_position_in_context_with_captured_scrollbar = *position_in_nested_context;+ }+ auto nested_result = context_with_captured_scrollbar->handle_mouse_event_from_containing_context(event_to_send, pointer.last_position_in_context_with_captured_scrollbar);+ auto result = result_of_nested_context(nested_context_id, *context_with_captured_scrollbar, nested_result, {});+ if (!context_with_captured_scrollbar->has_captured_scrollbar()) {+ pointer.context_with_captured_scrollbar.clear();+ context_with_captured_scrollbar = nullptr;+ pointer.context_under_pointer = nested_context_id;+ }+ return result;+ };++ // The scrollbar the pointer was over in the nested context it left is no longer hovered.+ auto note_context_under_pointer = [&](Optional<Web::CompositorContextId> nested_context_id) {+ if (pointer.context_under_pointer == nested_context_id)+ return;+ if (auto* context_left = context_still_nested_in(context_id, pointer.context_under_pointer)) {+ if (auto frame_to_present = context_left->clear_scrollbar_hover(); frame_to_present.has_value())+ schedule_present_frame(*pointer.context_under_pointer, *context_left, *frame_to_present);+ }+ pointer.context_under_pointer = nested_context_id;+ };++ switch (event.type) {+ case Type::MouseDown:+ case Type::MouseMove: {+ if (context_with_captured_scrollbar) {+ if (event.type == Type::MouseMove)+ return send_to_context_with_captured_scrollbar(event);+ // A press while a drag is still held means the release of that drag never came, so the drag ends there.+ auto cancel_event = event.clone_without_browser_data();+ cancel_event.type = Type::MouseCancel;+ (void)send_to_context_with_captured_scrollbar(cancel_event);+ }++ auto result = context.handle_mouse_event(event);+ if (!result.nested_context_mouse_hit.has_value()) {+ note_context_under_pointer({});+ return result;+ }++ auto frame_of_this_context = result.frame_to_present;+ auto containing_context_id = context_id;+ auto* containing_context = &context;+ Gfx::FloatPoint position;+ while (result.nested_context_mouse_hit.has_value()) {+ auto hit = *result.nested_context_mouse_hit;+ // WebContent names the contexts its display lists draw, so a context only reaches those nested in it.+ auto* nested_context = context_if_present(hit.child_context_id);+ Optional<Gfx::FloatPoint> position_in_nested_context_content;+ if (nested_context && nested_context->parent_context_id() == containing_context_id)+ position_in_nested_context_content = position_in_nested_context(hit, *nested_context);+ if (!position_in_nested_context_content.has_value()) {+ note_context_under_pointer({});+ auto declined = ContextState::ContextUpdateResult::declined(Web::InputRoutingDecision::NestedContextUnavailable);+ declined.frame_to_present = frame_of_this_context;+ declined.nested_context_hand_off = Web::InputRoutingDecision::HandedToNestedContext;+ return declined;+ }+ if (containing_context != &context) {+ apply_context_update_result(containing_context_id, *containing_context, result);+ schedule_animation_frames_if_needed(*containing_context);+ }+ containing_context_id = hit.child_context_id;+ containing_context = nested_context;+ position = *position_in_nested_context_content;+ result = nested_context->handle_mouse_event_from_containing_context(event, position);+ }++ note_context_under_pointer(containing_context_id);+ if (event.type == Type::MouseDown && containing_context->has_captured_scrollbar()) {+ pointer.context_with_captured_scrollbar = containing_context_id;+ pointer.last_position_in_context_with_captured_scrollbar = position;+ }+ return result_of_nested_context(containing_context_id, *containing_context, result, move(frame_of_this_context));+ }+ case Type::MouseUp:+ if (context_with_captured_scrollbar)+ return send_to_context_with_captured_scrollbar(event);+ return context.handle_mouse_event(event);+ case Type::MouseLeave:+ case Type::MouseCancel: {+ // The pointer leaves every nested context it was in, and a cancel ends the drag of one, as in this context.+ Optional<ContextState::ContextUpdateResult> result_of_context_with_captured_scrollbar;+ Optional<Web::CompositorContextId> context_with_captured_scrollbar_id;+ if (context_with_captured_scrollbar) {+ context_with_captured_scrollbar_id = pointer.context_with_captured_scrollbar;+ result_of_context_with_captured_scrollbar = send_to_context_with_captured_scrollbar(event);+ }+ if (auto* context_under_pointer = context_still_nested_in(context_id, pointer.context_under_pointer); context_under_pointer && pointer.context_under_pointer != context_with_captured_scrollbar_id) {+ auto nested_result = context_under_pointer->handle_mouse_event_from_containing_context(event, {});+ apply_context_update_result(*pointer.context_under_pointer, *context_under_pointer, nested_result);+ schedule_animation_frames_if_needed(*context_under_pointer);+ }+ pointer.context_under_pointer.clear();++ auto result = context.handle_mouse_event(event);+ if (!result_of_context_with_captured_scrollbar.has_value())+ return result;+ result_of_context_with_captured_scrollbar->frame_to_present = result.frame_to_present;+ return result_of_context_with_captured_scrollbar.release_value();+ }+ case Type::MouseWheel:+ return context.handle_mouse_event(event);+ }+ VERIFY_NOT_REACHED();+}+// Whether a context nested in the context `context_id` scrolled since the last frame its WebContent presented: the lane// of the context's document hands a pointer move to the lane of a same-process iframe, which hit tests it in the iframe.bool CompositorState::nested_context_scrolled_since_last_frame(Web::CompositorContextId context_id) const@@ -795,19 +993,7 @@ CompositorState::WheelStepHandedToNestedContext CompositorState::hand_wheel_stepreturn handed_step;}-// The content box of a nested context is drawn scaled to the size of its viewport.-static Optional<Gfx::FloatPoint> position_in_nested_context(Compositing::NestedContextWheelHit const& hit, ContextState const& nested_context)-{- auto viewport_size = nested_context.presenter().viewport_size().to_type<float>();- if (hit.content_box_size.is_empty() || viewport_size.is_empty())- return {};- return Gfx::FloatPoint {- hit.position_in_content_box.x() * viewport_size.width() / hit.content_box_size.width(),- hit.position_in_content_box.y() * viewport_size.height() / hit.content_box_size.height(),- };-}--Optional<CompositorState::NestedContextTakingWheelStep> CompositorState::nested_context_taking_first_wheel_step(Web::CompositorContextId context_id, Compositing::NestedContextWheelHit hit, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision wheel_delta_precision)+Optional<CompositorState::NestedContextTakingWheelStep> CompositorState::nested_context_taking_first_wheel_step(Web::CompositorContextId context_id, Compositing::NestedContextHit hit, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision wheel_delta_precision){using Kind = ContextState::FirstWheelStepRoute::Kind;// The contexts the step went into, outermost first, each nested in the one before.diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.hindex a45b87f4ff5..6b69888d654 100644--- a/Services/Compositor/CompositorState.h+++ b/Services/Compositor/CompositorState.h@@ -259,7 +259,14 @@ private:};// The context that takes the first step of a gesture over the content of a context nested in the context// `context_id`, among that context and the contexts nested in it. Empty when each of them passes the step on.- Optional<NestedContextTakingWheelStep> nested_context_taking_first_wheel_step(Web::CompositorContextId, Compositing::NestedContextWheelHit, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision);+ Optional<NestedContextTakingWheelStep> nested_context_taking_first_wheel_step(Web::CompositorContextId, Compositing::NestedContextHit, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision);+ // The scrollbars of a context nested in the presenting context `context_id` take the pointer over that context's+ // content, and a drag of one of them takes the pointer wherever it goes until the drag ends.+ ContextState::ContextUpdateResult handle_mouse_event_in_nested_contexts(Web::CompositorContextId, ContextState&, Web::MouseEvent const&);+ ContextState* context_still_nested_in(Web::CompositorContextId containing_context_id, Optional<Web::CompositorContextId>);+ // Where the position in the presenting context lands in the nested context, through each context in between and+ // without regard to where their content is or what clips it.+ Optional<Gfx::FloatPoint> position_in_nested_context_ignoring_clips(Web::CompositorContextId presenting_context_id, ContextState& presenting_context, ContextState& nested_context, Gfx::FloatPoint position);bool is_nested_in(Web::CompositorContextId containing_context_id, ContextState const&) const;bool nested_context_may_cancel_pinch(Web::CompositorContextId) const;void dispatch_scroll_fling_step(Web::CompositorContextId, ContextState&, Optional<Web::MouseEvent>, MonotonicTime now);diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cppindex e71c58630a3..6ea2bbd60f1 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -128,6 +128,7 @@ void ContextState::dispatch_pinch_event_to_web_content(Web::PinchEvent const& evvoid ContextState::stop_presenting_to_client(){+ m_pointer_in_nested_contexts = {};end_keyboard_scroll_gesture();m_elastic_overscroll_controller.forget();m_presenter.stop_presenting_to_client();@@ -422,19 +423,73 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEvestatic_cast<float>(event.position.x().value()),static_cast<float>(event.position.y().value()),};+ return handle_mouse_event_at(event, position);+}++ContextState::ContextUpdateResult ContextState::handle_mouse_event_from_containing_context(Web::MouseEvent const& event, Gfx::FloatPoint position)+{+ return handle_mouse_event_at(event, position);+}++// The compositor paints how its own scrollbars expand, outside of what damage tracking sees.+Optional<PendingFrame> ContextState::frame_repainting_scrollbars_painted_by_compositor() const+{+ if (m_async_scrolling_viewport_rect.is_empty())+ return {};+ return PendingFrame::repainting_everything(m_async_scrolling_viewport_rect);+}++Optional<PendingFrame> ContextState::clear_scrollbar_hover()+{+ if (!m_scrollbar_controller.set_hovered_scrollbar({}))+ return {};+ return frame_repainting_scrollbars_painted_by_compositor();+}++// The compositor paints its own scrollbars over everything, so a nested context only takes the pointer where none of+// them is under it, and where no scrollbar the display list paints comes after the nested context's content in paint+// order. A press passes by a scrollbar that has faded out, as it does here.+Optional<Compositing::NestedContextHit> ContextState::nested_context_taking_mouse_event_at(Web::MouseEvent::Type type, Gfx::FloatPoint position)+{+ if (!m_has_async_scrolling_state)+ return {};+ auto const& visual_context_tree = m_scene.visual_context_tree_for_compositing();+ auto hit = m_async_scroll_tree.nested_context_at(visual_context_tree, position);+ if (!hit.has_value())+ return {};+ if (auto scrollbar_index = m_scrollbar_controller.hit_test_scrollbar_painted_by_compositor(m_async_scroll_tree, m_scroll_state_snapshot, position); scrollbar_index.has_value()) {+ if (type != Web::MouseEvent::Type::MouseDown || m_scrollbar_controller.is_shown(*scrollbar_index))+ return {};+ }+ if (auto scrollbar_index = m_scrollbar_controller.hit_test_scrollbar_painted_by_display_list(m_async_scroll_tree, visual_context_tree, m_scroll_state_snapshot, position); scrollbar_index.has_value()) {+ if (m_scrollbar_controller.scrollbars()[*scrollbar_index].paint_order_index > hit->paint_order_index)+ return {};+ }+ return hit;+}- if (m_scrollbar_controller.is_empty())+Optional<Compositing::NestedContextHit> ContextState::position_in_content_of_nested_context(Web::CompositorContextId nested_context_id, Gfx::FloatPoint position)+{+ if (!m_has_async_scrolling_state)+ return {};+ return m_async_scroll_tree.position_in_content_of_nested_context(nested_context_id, m_scene.visual_context_tree_for_compositing(), position);+}++ContextState::ContextUpdateResult ContextState::handle_mouse_event_at(Web::MouseEvent const& event, Gfx::FloatPoint position)+{+ if (m_scrollbar_controller.is_empty() && !m_async_scroll_tree.has_nested_contexts())return ContextUpdateResult::declined(Web::InputRoutingDecision::NotOverAScrollbar);auto scroller_of_scrollbar = [&](size_t scrollbar_index) {return m_scrollbar_controller.scrollbars()[scrollbar_index].scroller_stable_node_id;};- // The compositor paints how its own scrollbars expand, outside of what damage tracking sees.- auto frame_repainting_scrollbars_painted_by_compositor = [&]() -> Optional<PendingFrame> {- if (m_async_scrolling_viewport_rect.is_empty())- return {};- return PendingFrame::repainting_everything(m_async_scrolling_viewport_rect);+ // The pointer goes on into a nested context, and leaves the scrollbar here it was over.+ auto hand_to_nested_context = [&](Compositing::NestedContextHit const& hit) {+ return ContextUpdateResult {+ .frame_to_present = clear_scrollbar_hover(),+ .nested_context_mouse_hit = hit,+ };};switch (event.type) {@@ -442,6 +497,9 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEveif (event.button != Web::UIEvents::MouseButton::Primary)return ContextUpdateResult::declined(Web::InputRoutingDecision::NotPrimaryButton);+ if (auto hit = nested_context_taking_mouse_event_at(event.type, position); hit.has_value())+ return hand_to_nested_context(*hit);+auto drag = m_scrollbar_controller.begin_drag(m_async_scroll_tree, m_scene.visual_context_tree_for_compositing(), m_scroll_state_snapshot, position);if (!drag.has_value())return ContextUpdateResult::declined(Web::InputRoutingDecision::NotOverAScrollbar);@@ -452,7 +510,7 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEveresult.accepted = true;result.routing_decision = Web::InputRoutingDecision::BeganScrollbarDrag;result.routed_scroller = scroller_of_scrollbar(drag->scrollbar_index);- result.scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list();+ result.scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list(m_context_id);if (!result.scrollbar_dragged_by_compositor.has_value())result.frame_to_present = frame_repainting_scrollbars_painted_by_compositor();@@ -499,7 +557,7 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEve}case Web::MouseEvent::Type::MouseMove: {if (m_scrollbar_controller.has_captured_scrollbar()) {- auto scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list();+ auto scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list(m_context_id);auto drag = m_scrollbar_controller.captured_drag(m_scene.visual_context_tree_for_compositing(), m_scroll_state_snapshot, position);VERIFY(drag.has_value());// While paging, the pointer only says where the thumb pages to.@@ -521,6 +579,9 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEve};}+ if (auto hit = nested_context_taking_mouse_event_at(event.type, position); hit.has_value())+ return hand_to_nested_context(*hit);+// The main thread hovers the scrollbars the display list paints.auto hovered_scrollbar_index = m_scrollbar_controller.hit_test_scrollbar_painted_by_compositor(m_async_scroll_tree, m_scroll_state_snapshot, position);Optional<PendingFrame> frame_to_present;@@ -541,7 +602,7 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEvereturn ContextUpdateResult::declined(Web::InputRoutingDecision::NotPrimaryButton);auto box_of_dragged_scrollbar = box_of_captured_scrollbar();- auto scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list();+ auto scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list(m_context_id);auto drag = m_scrollbar_controller.release_captured_drag(m_scene.visual_context_tree_for_compositing(), m_scroll_state_snapshot, position);auto was_paging = m_scrollbar_paging.has_value();stop_scrollbar_paging();@@ -582,7 +643,7 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEve.accepted = had_capture,.frame_to_present = frame_to_present,.should_request_rendering_update = false,- .scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list(),+ .scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list(m_context_id),.routing_decision = had_capture ? Web::InputRoutingDecision::LeftDuringScrollbarDrag : Web::InputRoutingDecision::NoScrollbarDrag,};}@@ -591,7 +652,7 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEve// counts as having left. The page still sees the cancel, so it is not accepted.auto was_dragging_scrollbar = m_scrollbar_controller.has_captured_scrollbar();auto box_of_dragged_scrollbar = box_of_captured_scrollbar();- auto scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list();+ auto scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list(m_context_id);(void)m_scrollbar_controller.release_captured_drag(m_scene.visual_context_tree_for_compositing(), m_scroll_state_snapshot, position);stop_scrollbar_paging();note_user_scroll_gesture_end_if_drag_ended(box_of_dragged_scrollbar);@@ -1520,6 +1581,7 @@ void ContextState::clear_per_test_input_state(){// A gesture held by fingers never ends by itself, so one a test left unended would take in the next test's steps.m_wheel_gesture_routing.forget_gesture();+ m_pointer_in_nested_contexts = {};m_last_reported_scroll_momentum_step.clear();m_reported_scroll_momentum_was_interrupted = false;}@@ -1670,7 +1732,7 @@ bool ContextState::may_hand_first_wheel_steps_to_nested_contexts() constreturn m_has_async_scrolling_state && m_scene.visual_viewport_scale().value_or(1.0f) == 1.0f;}-Optional<Compositing::NestedContextWheelHit> ContextState::nested_context_for_wheel_at(Gfx::FloatPoint position)+Optional<Compositing::NestedContextHit> ContextState::nested_context_for_wheel_at(Gfx::FloatPoint position){if (!m_has_async_scrolling_state)return {};@@ -1968,7 +2030,8 @@ Gfx::IntRect ContextState::update_scrollbar_visibility()}// NB: This goes on the connection the compositor forwards input on, so the main thread knows which scrollbars have-// faded out before it hit tests any later press.+// faded out before it hit tests any later press. A nested context another process owns reports to that process,+// which gets its input through the UI instead.void ContextState::report_scrollbar_visibility_changes(){auto changes = m_scrollbar_controller.take_visibility_changes();diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.hindex 7d4f4e08819..2adf81bcbc0 100644--- a/Services/Compositor/ContextState.h+++ b/Services/Compositor/ContextState.h@@ -75,7 +75,7 @@ public:struct NestedContextWheelStep {Web::CompositorContextId context_id;// Where the first step lands in the content of the nested context.- Optional<Compositing::NestedContextWheelHit> hit {};+ Optional<Compositing::NestedContextHit> hit {};};struct ContextUpdateResult {@@ -90,6 +90,9 @@ public:Optional<Web::InputRoutingDecision> nested_context_hand_off {};// Set instead of everything else for a wheel step that a nested context is to take.Optional<NestedContextWheelStep> nested_context_wheel_step {};+ // Set, with at most the frame of the scrollbar the pointer left here, for a mouse event that the nested context+ // under the pointer is to take.+ Optional<Compositing::NestedContextHit> nested_context_mouse_hit {};static ContextUpdateResult declined(Web::InputRoutingDecision decision) { return { .routing_decision = decision }; }};@@ -120,7 +123,7 @@ public:Web::InputRoutingDecision decision;Optional<Compositing::AsyncScrollNodeID> node_id {};Optional<Web::AsyncScrollNodeStableID> scroller {};- Optional<Compositing::NestedContextWheelHit> nested_context_hit {};+ 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 = {});@@ -161,6 +164,22 @@ public:ContextUpdateResult handle_key_event(Web::KeyEvent const&);Optional<Web::AsyncScrollNodeStableID> box_scrolled_for_key_event(Web::KeyEvent const&) const;ContextUpdateResult handle_mouse_event(Web::MouseEvent const&);+ // A mouse event that the context this one is nested in hands to it, at a position in this context's device pixels.+ ContextUpdateResult handle_mouse_event_from_containing_context(Web::MouseEvent const&, Gfx::FloatPoint position);+ bool has_captured_scrollbar() const { return m_scrollbar_controller.has_captured_scrollbar(); }+ // The pointer left the scrollbar it was over here for a context nested in this one, or for the one around it.+ Optional<PendingFrame> clear_scrollbar_hover();+ Optional<Compositing::NestedContextHit> position_in_content_of_nested_context(Web::CompositorContextId, Gfx::FloatPoint position);+ // What a presenting context keeps of the contexts nested in it that the pointer is in, with positions in the device+ // pixels of those contexts.+ struct PointerInNestedContexts {+ // The context whose scrollbar the pointer is dragging, which takes the pointer wherever it goes until the drag+ // ends.+ Optional<Web::CompositorContextId> context_with_captured_scrollbar;+ Gfx::FloatPoint last_position_in_context_with_captured_scrollbar;+ Optional<Web::CompositorContextId> context_under_pointer;+ };+ PointerInNestedContexts& pointer_in_nested_contexts() { return m_pointer_in_nested_contexts; }// The UI's wheel deltas are in CSS pixels; this scales them for the scroll tree, which works in device pixels.ContextUpdateResult handle_wheel_event(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});// Takes note of a wheel event from the UI as it arrives, ahead of anything that may turn it away or leave it to@@ -170,7 +189,7 @@ public:bool admits_async_pinch() const { return m_wheel_gesture_routing.admits_async_pinch(); }bool may_hand_first_wheel_steps_to_nested_contexts() const;- Optional<Compositing::NestedContextWheelHit> nested_context_for_wheel_at(Gfx::FloatPoint position);+ Optional<Compositing::NestedContextHit> nested_context_for_wheel_at(Gfx::FloatPoint position);ContextUpdateResult scroll_for_wheel_event_passed_on_by_nested_context(Web::MouseEvent const&, MonotonicTime now);void latch_wheel_gesture_to_nested_context(Web::CompositorContextId, Optional<Web::AsyncScrollNodeStableID> scroller, Web::MouseEvent const&);void forget_wheel_gesture_latch() { m_wheel_gesture_routing.clear_latch(); }@@ -362,6 +381,9 @@ private:// A gesture whose steps this context chains ends once they stop arriving, which is reported to WebContent so// that it settles the gesture then rather than on a clock of its own.void end_scroll_step_gestures_whose_input_ran_out(MonotonicTime now);+ ContextUpdateResult handle_mouse_event_at(Web::MouseEvent const&, Gfx::FloatPoint position);+ Optional<Compositing::NestedContextHit> nested_context_taking_mouse_event_at(Web::MouseEvent::Type, Gfx::FloatPoint position);+ Optional<PendingFrame> frame_repainting_scrollbars_painted_by_compositor() const;Optional<PendingFrame> apply_scrollbar_drag(ScrollbarController::Drag const&);Optional<PendingFrame> start_scrollbar_press_scroll(Compositing::AsyncScrollNode const&, Gfx::FloatPoint old_scroll_offset, Gfx::FloatPoint destination, bool is_absolute_scroll);Optional<PendingFrame> page_captured_scrollbar();@@ -415,6 +437,7 @@ private:Optional<ScrollbarPaging> m_scrollbar_paging;bool m_scrollbar_track_press_jumps { false };RefPtr<Core::Timer> m_scrollbar_paging_timer;+ PointerInNestedContexts m_pointer_in_nested_contexts;ScrollFlingController m_scroll_fling_controller;Optional<Web::MouseEvent> m_last_reported_scroll_momentum_step;bool m_reported_scroll_momentum_was_interrupted { false };diff --git a/Services/Compositor/ScrollbarController.cpp b/Services/Compositor/ScrollbarController.cppindex b84b6051f79..ca74e40dd39 100644--- a/Services/Compositor/ScrollbarController.cpp+++ b/Services/Compositor/ScrollbarController.cpp@@ -138,7 +138,7 @@ void ScrollbarController::set_scrollbars(Vector<Compositing::AsyncScrollbar> conm_thumb_grab_position = 0;}-Optional<Web::ScrollbarDraggedByCompositor> ScrollbarController::captured_scrollbar_painted_by_display_list() const+Optional<Web::ScrollbarDraggedByCompositor> ScrollbarController::captured_scrollbar_painted_by_display_list(Web::CompositorContextId context_id) const{if (!m_captured_scrollbar_index.has_value())return {};@@ -146,6 +146,7 @@ Optional<Web::ScrollbarDraggedByCompositor> ScrollbarController::captured_scrollif (scrollbar.is_painted_by_compositor || !scrollbar.scroller_stable_node_id.has_value())return {};return Web::ScrollbarDraggedByCompositor {+ .context_id = context_id,.scroller_stable_node_id = *scrollbar.scroller_stable_node_id,.vertical = scrollbar.vertical,};@@ -168,13 +169,13 @@ Optional<size_t> ScrollbarController::hit_test_scrollbar_painted_by_compositor(C}// A scrollbar the display list paints takes a press only where the main thread would give it one: inside the rect of-// the scrollbar as it is painted now, and with nothing that takes pointer input painted over it there. Any other press-// is left to the main thread.+// the scrollbar as it is painted now, and with nothing that takes pointer input painted over it there. A scrollbar that+// has faded out takes none, as the main thread passes it by. Any other press is left to the main thread.Optional<size_t> ScrollbarController::hit_test_scrollbar_painted_by_display_list(Compositing::AsyncScrollTree const& async_scroll_tree, Compositing::AccumulatedVisualContextTree const& visual_context_tree, Compositing::ScrollStateSnapshot const& scroll_state_snapshot, Gfx::FloatPoint position) const{for (size_t i = m_scrollbars.size(); i-- > 0;) {auto const& scrollbar = m_scrollbars[i];- if (scrollbar.is_painted_by_compositor || !scrollbar.scroller_stable_node_id.has_value())+ if (scrollbar.is_painted_by_compositor || !scrollbar.scroller_stable_node_id.has_value() || !is_shown(i))continue;if (!async_scroll_tree.scroll_offset_for_node(scrollbar.scroll_node_id, scroll_state_snapshot).has_value())continue;diff --git a/Services/Compositor/ScrollbarController.h b/Services/Compositor/ScrollbarController.hindex e37074b3a3e..c47a09edd9d 100644--- a/Services/Compositor/ScrollbarController.h+++ b/Services/Compositor/ScrollbarController.h@@ -93,10 +93,15 @@ public:// Which way a press beside the thumb pages: -1 or 1 toward the pointer from where the thumb is at the given scroll// offset, or 0 when the thumb is under the pointer.int paging_direction(size_t scrollbar_index, float primary_position, Gfx::FloatPoint scroll_offset) const;- // The main thread still takes the mouse events of a drag that holds a scrollbar the display list paints.- Optional<Web::ScrollbarDraggedByCompositor> captured_scrollbar_painted_by_display_list() const;+ // The main thread still takes the mouse events of a drag that holds a scrollbar the display list paints. The+ // context is the one this controller belongs to.+ Optional<Web::ScrollbarDraggedByCompositor> captured_scrollbar_painted_by_display_list(Web::CompositorContextId) const;Optional<size_t> hit_test_scrollbar_painted_by_compositor(Compositing::AsyncScrollTree const&, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position) const;+ // A scrollbar the display list paints takes the pointer only where the main thread would give it to it.+ Optional<size_t> hit_test_scrollbar_painted_by_display_list(Compositing::AsyncScrollTree const&, Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position) const;+ // Whether the scrollbar is shown, rather than hidden until its scroller next scrolls.+ bool is_shown(size_t scrollbar_index) const { return opacity(scrollbar_index) > 0; }Optional<Drag> begin_drag(Compositing::AsyncScrollTree const&, Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position);Optional<Drag> captured_drag(Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position);Optional<Drag> release_captured_drag(Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position);@@ -124,7 +129,6 @@ private:float expansion(size_t scrollbar_index) const;PresentedScrollbar presented_scrollbar(size_t scrollbar_index, Compositing::ScrollStateSnapshot const&, Color thumb_color, Color track_color) const;Optional<Gfx::IntRect> rect_in_viewport(size_t scrollbar_index, Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot const&) const;- Optional<size_t> hit_test_scrollbar_painted_by_display_list(Compositing::AsyncScrollTree const&, Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position) const;float primary_position_of_captured_drag(Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position);Vector<Compositing::AsyncScrollbar> m_scrollbars;diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/scrollbar-drag-in-an-isolated-iframe.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/scrollbar-drag-in-an-isolated-iframe.txtnew file mode 100644index 00000000000..0a5aa6c2fd5--- /dev/null+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/scrollbar-drag-in-an-isolated-iframe.txt@@ -0,0 +1,25 @@+#1 compositor: handed-to-nested-context+#1 compositor: not-over-a-scrollbar+#1 compositor: forwarded-to-page+#1 web-content: forwarded-to-remote-frame+#2 compositor: handed-to-nested-context+#2 compositor: began-scrollbar-drag+#2 compositor: forwarded-to-page+#2 web-content: forwarded-to-remote-frame+#3 compositor: handed-to-nested-context+#3 compositor: continued-scrollbar-drag+#3 compositor: forwarded-to-page+#3 web-content: forwarded-to-remote-frame+#4 compositor: handed-to-nested-context+#4 compositor: continued-scrollbar-drag+#4 compositor: forwarded-to-page+#4 web-content: finished-handled+#5 compositor: handed-to-nested-context+#5 compositor: ended-scrollbar-drag+#5 compositor: forwarded-to-page+#5 web-content: finished-handled+the scroller in the frame's document scrolled to: 900+pointerdown reached: scroller+this document did not scroll: true+WebContent#0+ iframe#0: remote WebContent#1diff --git a/Tests/LibWeb/Text/expected/UIEvents/scrollbar-drag-in-iframe-driven-by-compositor.txt b/Tests/LibWeb/Text/expected/UIEvents/scrollbar-drag-in-iframe-driven-by-compositor.txtnew file mode 100644index 00000000000..7ce25613367--- /dev/null+++ b/Tests/LibWeb/Text/expected/UIEvents/scrollbar-drag-in-iframe-driven-by-compositor.txt@@ -0,0 +1,24 @@+#1 compositor: handed-to-nested-context+#1 compositor: not-over-a-scrollbar+#1 compositor: forwarded-to-page+#1 web-content: finished-handled+#2 compositor: handed-to-nested-context+#2 compositor: began-scrollbar-drag scroller=#scroller+#2 compositor: forwarded-to-page+#2 web-content: scrollbar-drag-driven-by-compositor scroller=#scroller+#2 web-content: finished-handled+#3 compositor: handed-to-nested-context+#3 compositor: continued-scrollbar-drag scroller=#scroller+#3 compositor: forwarded-to-page+#3 web-content: finished-handled+#4 compositor: handed-to-nested-context+#4 compositor: continued-scrollbar-drag scroller=#scroller+#4 compositor: forwarded-to-page+#4 web-content: finished-handled+#5 compositor: handed-to-nested-context+#5 compositor: ended-scrollbar-drag scroller=#scroller+#5 compositor: forwarded-to-page+#5 web-content: finished-handled+pointerdown reached the scroller in the iframe: true+scrollTop after the drag: 900+this document did not scroll: truediff --git a/Tests/LibWeb/Text/expected/UIEvents/scrollbar-press-goes-to-what-is-painted-over-an-iframe.txt b/Tests/LibWeb/Text/expected/UIEvents/scrollbar-press-goes-to-what-is-painted-over-an-iframe.txtnew file mode 100644index 00000000000..7770872f28a--- /dev/null+++ b/Tests/LibWeb/Text/expected/UIEvents/scrollbar-press-goes-to-what-is-painted-over-an-iframe.txt@@ -0,0 +1,3 @@+the scroller around the iframe scrolled: true+the scroller under the iframe did not scroll: true+the scroller in the iframe scrolled: truediff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/scrollbar-drag-in-an-isolated-iframe.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/scrollbar-drag-in-an-isolated-iframe.htmlnew file mode 100644index 00000000000..4d4ca30fa35--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/scrollbar-drag-in-an-isolated-iframe.html@@ -0,0 +1,68 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<style>+ body { margin: 0; }+ iframe { display: block; width: 200px; height: 150px; border: 0; }+</style>+<script>+ // The drag goes through the UI process to the Compositor, which drags the scrollbar of the frame's document for the+ // process hosting it. The press still reaches that document's scroller, through the UI process.+ promiseTest(async () => {+ const remoteUrl = new URL(+ await httpTestServer().createEcho("GET", "/oop-iframe-scrollbar-drag", {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html><style>+ body { margin: 0; }+ #scroller { width: 150px; height: 100px; overflow-y: scroll; overflow-x: hidden; }+ #content { height: 1000px; }+ </style><div id="scroller"><div id="content"></div></div><script>+ let pointerDownTarget = "none";+ scroller.addEventListener("pointerdown", event => (pointerDownTarget = event.target.id));+ const afterTwoFrames = callback => requestAnimationFrame(() => requestAnimationFrame(callback));+ addEventListener("message", event => {+ if (event.data === "report")+ afterTwoFrames(() => parent.postMessage({ scrollTop: scroller.scrollTop, pointerDownTarget }, "*"));+ });+ // The compositor has this document's scrollbar before the drag starts.+ afterTwoFrames(() => {+ internals.synchronizeCompositor();+ parent.postMessage("ready", "*");+ });+ <\/script>`,+ })+ );+ remoteUrl.hostname = uniqueLocalhostHostname("oop-iframe-scrollbar-drag");++ const nextMessage = () => new Promise(resolve => window.addEventListener("message", event => resolve(event.data), { once: true }));++ const ready = nextMessage();+ const iframe = document.createElement("iframe");+ iframe.src = remoteUrl;+ document.body.appendChild(iframe);+ await ready;+ // The frame's document came in a process of its own, which this document draws the frame from once it has+ // rendered again.+ await animationFrame();+ await animationFrame();++ // The output element is above the iframe and grows with each line, so nothing is printed before the drag.+ const rect = iframe.getBoundingClientRect();+ const x = rect.left + 147;+ internals.beginInputTrace();+ await internals.mouseEventThroughUIProcess("mousemove", x, rect.top + 5);+ await internals.mouseEventThroughUIProcess("mousedown", x, rect.top + 5);+ await internals.mouseEventThroughUIProcess("mousemove", x, rect.top + 60, { buttons: 1 });+ await internals.mouseEventThroughUIProcess("mousemove", x + 150, rect.top + 250, { buttons: 1 });+ await internals.mouseEventThroughUIProcess("mouseup", x + 150, rect.top + 250);++ printInputTrace(internals.takeInputTrace());+ const report = nextMessage();+ iframe.contentWindow.postMessage("report", "*");+ const { scrollTop, pointerDownTarget } = await report;+ println(`the scroller in the frame's document scrolled to: ${scrollTop}`);+ println(`pointerdown reached: ${pointerDownTarget}`);+ println(`this document did not scroll: ${window.scrollY === 0}`);+ println(internals.dumpSiteIsolationProcessTree().trimEnd());+ });+</script>diff --git a/Tests/LibWeb/Text/input/UIEvents/scrollbar-drag-in-iframe-driven-by-compositor.html b/Tests/LibWeb/Text/input/UIEvents/scrollbar-drag-in-iframe-driven-by-compositor.htmlnew file mode 100644index 00000000000..b8853b71b06--- /dev/null+++ b/Tests/LibWeb/Text/input/UIEvents/scrollbar-drag-in-iframe-driven-by-compositor.html@@ -0,0 +1,50 @@+<!DOCTYPE html>+<style>+ body {+ margin: 0;+ }+ iframe {+ display: block;+ width: 200px;+ height: 150px;+ border: 0;+ margin-left: 30px;+ margin-top: 20px;+ }+</style>+<script src="../include.js"></script>+<script>+ promiseTest(async () => {+ const iframe = document.createElement("iframe");+ const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));+ iframe.srcdoc = `<!DOCTYPE html><style>+ body { margin: 0; }+ #scroller { width: 150px; height: 100px; overflow-y: scroll; overflow-x: hidden; }+ #content { height: 1000px; }+ </style><div id="scroller"><div id="content"></div></div>`;+ document.body.appendChild(iframe);+ await loaded;+ await animationFrame();+ await animationFrame();++ const scroller = iframe.contentDocument.getElementById("scroller");+ let pointerDownCount = 0;+ scroller.addEventListener("pointerdown", () => ++pointerDownCount);++ // The compositor of the iframe's document drags the scrollbar, and the drag goes on after the pointer leaves+ // the iframe.+ const rect = iframe.getBoundingClientRect();+ const x = rect.left + 147;+ internals.beginInputTrace();+ await internals.mouseEventThroughUIProcess("mousemove", x, rect.top + 5);+ await internals.mouseEventThroughUIProcess("mousedown", x, rect.top + 5);+ await internals.mouseEventThroughUIProcess("mousemove", x, rect.top + 60, { buttons: 1 });+ await internals.mouseEventThroughUIProcess("mousemove", x + 150, rect.top + 250, { buttons: 1 });+ await internals.mouseEventThroughUIProcess("mouseup", x + 150, rect.top + 250);+ printInputTrace(internals.takeInputTrace());+ await animationFrame();+ println(`pointerdown reached the scroller in the iframe: ${pointerDownCount === 1}`);+ println(`scrollTop after the drag: ${scroller.scrollTop}`);+ println(`this document did not scroll: ${window.scrollY === 0}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/UIEvents/scrollbar-press-goes-to-what-is-painted-over-an-iframe.html b/Tests/LibWeb/Text/input/UIEvents/scrollbar-press-goes-to-what-is-painted-over-an-iframe.htmlnew file mode 100644index 00000000000..ab513b190e5--- /dev/null+++ b/Tests/LibWeb/Text/input/UIEvents/scrollbar-press-goes-to-what-is-painted-over-an-iframe.html@@ -0,0 +1,84 @@+<!DOCTYPE html>+<style>+ body {+ margin: 0;+ }+ .scroller {+ width: 150px;+ height: 100px;+ overflow-y: scroll;+ overflow-x: hidden;+ }+ iframe {+ display: block;+ border: 0;+ }+ #scroller-around-iframe iframe {+ width: 150px;+ height: 1000px;+ }+ #covered-scroller {+ position: absolute;+ left: 0;+ top: 150px;+ }+ #covering-iframe {+ position: absolute;+ left: 120px;+ top: 150px;+ width: 100px;+ height: 100px;+ }+ .content {+ height: 1000px;+ }+</style>+<div id="scroller-around-iframe" class="scroller"></div>+<div id="covered-scroller" class="scroller"><div class="content"></div></div>+<script src="../include.js"></script>+<script>+ function loadIframe(iframe, parent) {+ const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));+ iframe.srcdoc = `<!DOCTYPE html><style>+ body { margin: 0; }+ #scroller { width: 30px; height: 100px; overflow-y: scroll; overflow-x: hidden; }+ #content { height: 1000px; }+ </style><div id="scroller"><div id="content"></div></div>`;+ parent.appendChild(iframe);+ return loaded;+ }++ // Drags down from near the top right corner of the element, where its vertical scrollbar's thumb is.+ async function dragFromTopRightCornerOf(element) {+ const rect = element.getBoundingClientRect();+ const x = rect.right - 3;+ await internals.mouseEventThroughUIProcess("mousemove", x, rect.top + 5);+ await internals.mouseEventThroughUIProcess("mousedown", x, rect.top + 5);+ await internals.mouseEventThroughUIProcess("mousemove", x, rect.top + 60, { buttons: 1 });+ await internals.mouseEventThroughUIProcess("mouseup", x, rect.top + 60);+ await animationFrame();+ }++ promiseTest(async () => {+ const iframeInScroller = document.createElement("iframe");+ await loadIframe(iframeInScroller, document.getElementById("scroller-around-iframe"));+ const coveringIframe = document.createElement("iframe");+ coveringIframe.id = "covering-iframe";+ await loadIframe(coveringIframe, document.body);+ await animationFrame();+ await animationFrame();++ // The scrollbar of a scroller is painted over the iframe in its content, so the scroller takes the drag.+ const scrollerAroundIframe = document.getElementById("scroller-around-iframe");+ await dragFromTopRightCornerOf(scrollerAroundIframe);+ println(`the scroller around the iframe scrolled: ${scrollerAroundIframe.scrollTop > 0}`);++ // An iframe painted over the scrollbar of a scroller takes the press, and the scrollbar of the iframe's own+ // scroller under the pointer takes the drag.+ const coveredScroller = document.getElementById("covered-scroller");+ const scrollerInCoveringIframe = coveringIframe.contentDocument.getElementById("scroller");+ await dragFromTopRightCornerOf(coveredScroller);+ println(`the scroller under the iframe did not scroll: ${coveredScroller.scrollTop === 0}`);+ println(`the scroller in the iframe scrolled: ${scrollerInCoveringIframe.scrollTop > 0}`);+ });+</script>