Truly independent web browser
LibWeb: Stop dragging scrollbars on the main thread
Aliaksandr Kalenik357b9be7bbb1
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 7d0fcb876d3..52748cf3aa2 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -7985,12 +7985,10 @@ bool LocalNavigable::has_inclusive_ancestor_with_visibility_hidden() constreturn false;}-UserScrollGestureHold::UserScrollGestureHold(LocalNavigable& navigable, TakesOverMomentum takes_over_momentum, Optional<Web::AsyncScrollNodeStableID> held_box)+UserScrollGestureHold::UserScrollGestureHold(LocalNavigable& navigable, TakesOverMomentum takes_over_momentum): m_navigable(navigable), m_takes_over_momentum(takes_over_momentum){- if (held_box.has_value())- hold(held_box.value());}UserScrollGestureHold::~UserScrollGestureHold()diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.hindex d9919f6fad3..8cf68e6e293 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.h+++ b/Libraries/LibWeb/HTML/LocalNavigable.h@@ -760,8 +760,8 @@ private:static FinishedScroll finished_scroll(MainThreadSmoothScroll const&);};-// Held user input, such as a pressed key or a grabbed scrollbar thumb, keeps the gesture of each box it holds going until-// it is released.+// Held user input, such as a pressed key or a scrollbar thumb the compositor drags, keeps the gesture of each box it+// holds going until it is released.class WEB_API UserScrollGestureHold {AK_MAKE_NONCOPYABLE(UserScrollGestureHold);AK_MAKE_NONMOVABLE(UserScrollGestureHold);@@ -774,7 +774,7 @@ public:No,Yes,};- explicit UserScrollGestureHold(LocalNavigable&, TakesOverMomentum = TakesOverMomentum::No, Optional<Web::AsyncScrollNodeStableID> held_box = {});+ explicit UserScrollGestureHold(LocalNavigable&, TakesOverMomentum = TakesOverMomentum::No);~UserScrollGestureHold();void hold(Web::AsyncScrollNodeStableID);diff --git a/Libraries/LibWeb/Painting/ChromeWidget.cpp b/Libraries/LibWeb/Painting/ChromeWidget.cppindex bcb9837e228..068d49f89ac 100644--- a/Libraries/LibWeb/Painting/ChromeWidget.cpp+++ b/Libraries/LibWeb/Painting/ChromeWidget.cpp@@ -4,13 +4,9 @@* SPDX-License-Identifier: BSD-2-Clause*/-#include <AK/GenericShorthands.h>-#include <LibCompositing/Scrolling/ScrollState.h>#include <LibWeb/DOM/Document.h>#include <LibWeb/Layout/Node.h>-#include <LibWeb/Page/Page.h>#include <LibWeb/Painting/BoxViews.h>-#include <LibWeb/Painting/ChromeMetrics.h>#include <LibWeb/Painting/ChromeWidget.h>#include <LibWeb/Painting/ResizeHandle.h>#include <LibWeb/Painting/Scrollbar.h>@@ -107,26 +103,4 @@ PhysicalResizeAxes physical_resize_axes(Layout::Node const& node)return { axes.horizontal, axes.vertical };}-Optional<ScrollbarData> compute_scrollbar_data(Layout::Node const& node, ScrollDirection direction, ChromeMetrics const& metrics, Compositing::ScrollStateSnapshot const* scroll_state_snapshot, ScrollbarSizing scrollbar_sizing)-{- float device_scroll_offset = 0;- if (scroll_state_snapshot) {- auto own_offset = scroll_state_snapshot->device_offset_for_index(own_scroll_node_index(node));- device_scroll_offset = direction == ScrollDirection::Horizontal ? -own_offset.x() : -own_offset.y();- }- Layout::RustFFI::FfiOptionalScrollbarData result;- Layout::RustFFI::layout_row_paintable_compute_scrollbar_data(- node.document_host(), committed_row_slot(node), static_cast<Layout::RustFFI::ScrollDirection>(direction),- metrics, scrollbar_sizing == ScrollbarSizing::Enlarged, scroll_state_snapshot, device_scroll_offset,- node.document().page().client().device_pixels_per_css_pixel(), &result);- if (!result.has_value)- return {};- return ScrollbarData {- .gutter_rect = result.value.gutter_rect,- .thumb_rect = result.value.thumb_rect,- .track_rect = result.value.track_rect,- .thumb_travel_to_scroll_ratio = result.value.thumb_travel_to_scroll_ratio,- };-}-}diff --git a/Libraries/LibWeb/Painting/ChromeWidget.h b/Libraries/LibWeb/Painting/ChromeWidget.hindex 734b5b5b8bf..35a63acc5be 100644--- a/Libraries/LibWeb/Painting/ChromeWidget.h+++ b/Libraries/LibWeb/Painting/ChromeWidget.h@@ -20,12 +20,6 @@#include <LibWeb/Painting/Scrolling.h>#include <LibWebCommon/PixelUnits.h>-namespace Web {--struct ChromeMetrics;--}-namespace Web::Painting {enum class MouseAction : u8 {@@ -43,24 +37,11 @@ enum class ChromeWidgetKind : u8 {VerticalScrollbar,};-struct ScrollbarData {- CSSPixelRect gutter_rect;- CSSPixelRect thumb_rect;- CSSPixelRect track_rect;- CSSPixelFraction thumb_travel_to_scroll_ratio { 0 };-};--enum class ScrollbarSizing {- Regular,- Enlarged,-};-struct PhysicalResizeAxes {bool horizontal;bool vertical;};-Optional<ScrollbarData> compute_scrollbar_data(Layout::Node const&, ScrollDirection, ChromeMetrics const&, Compositing::ScrollStateSnapshot const* = nullptr, ScrollbarSizing = ScrollbarSizing::Regular);PhysicalResizeAxes physical_resize_axes(Layout::Node const&);class Scrollbar;diff --git a/Libraries/LibWeb/Painting/Scrollbar.cpp b/Libraries/LibWeb/Painting/Scrollbar.cppindex 9cd9ef34c4c..21473417070 100644--- a/Libraries/LibWeb/Painting/Scrollbar.cpp+++ b/Libraries/LibWeb/Painting/Scrollbar.cpp@@ -35,48 +35,21 @@ void Scrollbar::begin_drag_driven_by_compositor()Painting::set_needs_repaint(*node, InvalidateDisplayList::PaintCommands);}-MouseAction Scrollbar::handle_pointer_event(Utf16FlyString const& type, unsigned button, CSSPixelPoint visual_viewport_position)+MouseAction Scrollbar::handle_pointer_event(Utf16FlyString const& type, unsigned button, CSSPixelPoint){- if (m_drag_is_driven_by_compositor) {- if (type != UIEvents::EventNames::pointerup || button != UIEvents::MouseButton::Primary)- return MouseAction::CaptureInput;- release_thumb_grab();- if (auto* node = layout_node())- Painting::set_needs_repaint(*node, InvalidateDisplayList::PaintCommands);+ if (!m_drag_is_driven_by_compositor)return MouseAction::None;- }-- if (type == UIEvents::EventNames::pointermove || type == UIEvents::EventNames::pointerup) {- if (!m_thumb_grab_position.has_value())- return MouseAction::None;- }- if (type != UIEvents::EventNames::pointermove && button != UIEvents::MouseButton::Primary)- return MouseAction::None;-- auto* node = layout_node();- if (!node) {- release_thumb_grab();- return MouseAction::None;- }-- auto position = Painting::transform_to_local_coordinates(*node, visual_viewport_position);- if (!scroll_to_mouse_position(position) && !m_thumb_grab_position.has_value())- return MouseAction::None;- Painting::set_needs_repaint(*node, InvalidateDisplayList::PaintCommands);-- if (type == UIEvents::EventNames::pointerup) {- release_thumb_grab();- return MouseAction::None;- }-- return MouseAction::CaptureInput;+ if (type != UIEvents::EventNames::pointerup || button != UIEvents::MouseButton::Primary)+ return MouseAction::CaptureInput;+ release_drag();+ if (auto* node = layout_node())+ Painting::set_needs_repaint(*node, InvalidateDisplayList::PaintCommands);+ return MouseAction::None;}-void Scrollbar::release_thumb_grab()+void Scrollbar::release_drag(){m_drag_is_driven_by_compositor = false;- m_thumb_grab_position.clear();- m_thumb_grab_gesture_hold = nullptr;push_enlarged_state();}@@ -109,66 +82,10 @@ void Scrollbar::mouse_leave()Painting::set_needs_repaint(*node, InvalidateDisplayList::PaintCommands);}-bool Scrollbar::scroll_to_mouse_position(CSSPixelPoint position)-{- auto* node = layout_node();- if (!node)- return false;- ChromeMetrics metrics = node->document().page().chrome_metrics();-- auto const& scroll_state = node->document().scroll_state_snapshot();- auto scrollbar_data = compute_scrollbar_data(*node, m_direction, metrics, &scroll_state,- is_enlarged() ? ScrollbarSizing::Enlarged : ScrollbarSizing::Regular);- if (!scrollbar_data.has_value())- return false;-- auto orientation = m_direction == ScrollDirection::Horizontal ? Orientation::Horizontal : Orientation::Vertical;- auto offset_relative_to_gutter = (position - scrollbar_data->gutter_rect.location()).primary_offset_for_orientation(orientation);- auto gutter_size = scrollbar_data->gutter_rect.primary_size_for_orientation(orientation);- auto thumb_size = scrollbar_data->thumb_rect.primary_size_for_orientation(orientation);-- if (gutter_size <= thumb_size)- return true;-- if (!m_thumb_grab_position.has_value()) {- auto primary_position = position.primary_offset_for_orientation(orientation);- auto position_is_along_thumb = orientation == Orientation::Vertical- ? scrollbar_data->thumb_rect.contains_vertically(primary_position)- : scrollbar_data->thumb_rect.contains_horizontally(primary_position);-- m_thumb_grab_position = position_is_along_thumb- ? (position - scrollbar_data->thumb_rect.location()).primary_offset_for_orientation(orientation)- : max(min(offset_relative_to_gutter, thumb_size / 2), offset_relative_to_gutter - gutter_size + thumb_size);- push_enlarged_state();- if (auto navigable = node->document().navigable())- m_thumb_grab_gesture_hold = make<HTML::UserScrollGestureHold>(*navigable, HTML::UserScrollGestureHold::TakesOverMomentum::No, async_scroll_node_stable_id(*node));- }-- auto constrained_offset = AK::clamp(offset_relative_to_gutter - m_thumb_grab_position.value(), 0, gutter_size - thumb_size);- auto scroll_position = constrained_offset.to_double() / (gutter_size - thumb_size).to_double();-- auto scrollable_overflow_size = Painting::scrollable_overflow_rect(*node)->primary_size_for_orientation(orientation);- auto padding_size = Painting::absolute_padding_box_rect(*node).primary_size_for_orientation(orientation);- auto minimum_scroll_offset = Painting::minimum_scroll_offset(*node).primary_offset_for_orientation(orientation);- auto scroll_position_in_pixels = minimum_scroll_offset + CSSPixels::nearest_value_for(scroll_position * (scrollable_overflow_size - padding_size));-- auto new_scroll_offset = Painting::scroll_offset(*node);- new_scroll_offset.set_primary_offset_for_orientation(orientation, scroll_position_in_pixels);-- // https://drafts.csswg.org/css-scroll-snap-1/#scroll-types- // Common examples of absolute scrolls include:- // manipulating the scrollbar "thumb" explicitly- if (auto navigable = node->document().navigable())- navigable->note_user_scroll_input_intent(Compositing::SnapSelectionStrategy::Type::EndPosition);-- Painting::set_scroll_offset_from_user_input(*node, new_scroll_offset, Painting::ScrollKind::Absolute);- return true;-}-void Scrollbar::did_detach(){m_hovered = false;- release_thumb_grab();+ release_drag();}}diff --git a/Libraries/LibWeb/Painting/Scrollbar.h b/Libraries/LibWeb/Painting/Scrollbar.hindex ff0c6367203..a68a72a8b0e 100644--- a/Libraries/LibWeb/Painting/Scrollbar.h+++ b/Libraries/LibWeb/Painting/Scrollbar.h@@ -6,7 +6,6 @@#pragma once-#include <AK/OwnPtr.h>#include <LibWeb/Painting/ChromeWidget.h>namespace Web::Painting {@@ -15,7 +14,7 @@ class Scrollbar final : public ChromeWidget {public:static NonnullRefPtr<Scrollbar> create(Layout::NodeArena&, Compositing::RustFFI::NodeSlotId, ScrollDirection);- bool is_enlarged() const { return m_hovered || m_thumb_grab_position.has_value() || m_drag_is_driven_by_compositor; }+ bool is_enlarged() const { return m_hovered || m_drag_is_driven_by_compositor; }// The compositor scrolls for a drag it drives, and this scrollbar only keeps looking dragged until the release.void begin_drag_driven_by_compositor();@@ -27,16 +26,13 @@ public:private:Scrollbar(Layout::NodeArena&, Compositing::RustFFI::NodeSlotId, ScrollDirection);- bool scroll_to_mouse_position(CSSPixelPoint);- void release_thumb_grab();+ void release_drag();void push_enlarged_state();virtual void did_detach() override;ScrollDirection m_direction;bool m_hovered { false };bool m_drag_is_driven_by_compositor { false };- Optional<CSSPixels> m_thumb_grab_position;- OwnPtr<HTML::UserScrollGestureHold> m_thumb_grab_gesture_hold;};}diff --git a/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs b/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rsindex 2aa2b786b8c..ea6e882c68f 100644--- a/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs+++ b/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs@@ -26,12 +26,6 @@ pub(crate) struct ScrollbarData {pub(crate) thumb_travel_to_scroll_ratio: CssPixelFraction,}-#[derive(Clone, Copy, Debug)]-pub(crate) struct ScrollbarScrollState {- pub(crate) device_scroll_offset: f32,- pub(crate) device_pixels_per_css_pixel: f64,-}-#[derive(Clone, Copy, Debug, Default)]pub(crate) struct PhysicalAxes {pub(crate) horizontal: bool,@@ -399,7 +393,6 @@ impl<'a, Arena: PaintRead> ChromeGeometry<'a, Arena> {slot: NodeSlotId,direction: ScrollDirection,enlarged: bool,- scroll_state: Option<ScrollbarScrollState>,) -> Option<ScrollbarData> {let arena = self.arena;let metrics = self.metrics;@@ -450,12 +443,6 @@ impl<'a, Arena: PaintRead> ChromeGeometry<'a, Arena> {if enlarged || (direction == ScrollDirection::Vertical && is_chrome_mirrored(arena, slot)) {*thumb.secondary_offset += thumb_margin;}- if let Some(scroll_state) = scroll_state {- let scroll_offset = CssPixels::nearest_value_for_f32(- scroll_state.device_scroll_offset / scroll_state.device_pixels_per_css_pixel as f32,- );- *thumb.primary_offset += scroll_offset.mul_by_fraction(ratio);- }Some(ScrollbarData {gutter_rect: if enlarged {scrollbar_rectdiff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex 39061e9d45a..2db598d21dd 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -84,22 +84,6 @@ pub struct FfiPhysicalResizeAxes {pub vertical: bool,}-#[derive(Clone, Copy, Debug, Default)]-#[repr(C)]-pub struct FfiScrollbarData {- pub gutter_rect: FfiCssPixelRect,- pub thumb_rect: FfiCssPixelRect,- pub track_rect: FfiCssPixelRect,- pub thumb_travel_to_scroll_ratio: f64,-}--#[derive(Clone, Copy, Debug, Default)]-#[repr(C)]-pub struct FfiOptionalScrollbarData {- pub has_value: bool,- pub value: FfiScrollbarData,-}-/// # Safety////// `host` must be a live document host, on its document's thread.diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rsindex 42e72a76fcb..509c576e614 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs@@ -39,44 +39,6 @@ pub extern "C" fn layout_row_paintable_physical_resize_axes(}}-#[unsafe(no_mangle)]-pub extern "C" fn layout_row_paintable_compute_scrollbar_data(- host: &crate::render_state::DocumentHost,- slot: NodeSlotId,- direction: ScrollDirection,- metrics: FfiChromeMetrics,- enlarged: bool,- has_device_scroll_offset: bool,- device_scroll_offset: f32,- device_pixels_per_css_pixel: f64,- out: &mut FfiOptionalScrollbarData,-) {- let data = read_measured_rows(host, super::node_read(), |rows| {- crate::painting::chrome_geometry::ChromeGeometry { arena: rows, metrics }.compute_scrollbar_data(- slot,- direction,- enlarged,- has_device_scroll_offset.then_some(crate::painting::chrome_geometry::ScrollbarScrollState {- device_scroll_offset,- device_pixels_per_css_pixel,- }),- )- });- let Some(data) = data else {- *out = FfiOptionalScrollbarData::default();- return;- };- *out = FfiOptionalScrollbarData {- has_value: true,- value: FfiScrollbarData {- gutter_rect: data.gutter_rect.into(),- thumb_rect: data.thumb_rect.into(),- track_rect: data.track_rect.into(),- thumb_travel_to_scroll_ratio: data.thumb_travel_to_scroll_ratio.to_double(),- },- };-}-#[unsafe(no_mangle)]pub extern "C" fn layout_row_paintable_minimum_scroll_offset(host: &crate::render_state::DocumentHost,diff --git a/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rs b/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rsindex 86f77b350e3..2137f1a1b3b 100644--- a/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rs@@ -347,9 +347,9 @@ impl<O: Observer> PaintRecorder<'_, O> {display_list_paints_enlarged_scrollbar: bool,) -> Option<CompositorScrollbar> {let chrome_geometry = ChromeGeometry::for_recording(self.source, self.inputs);- let scrollbar = chrome_geometry.compute_scrollbar_data(paintable, direction, false, None)?;+ let scrollbar = chrome_geometry.compute_scrollbar_data(paintable, direction, false)?;let expanded = chrome_geometry- .compute_scrollbar_data(paintable, direction, true, None)+ .compute_scrollbar_data(paintable, direction, true).expect("an enlarged scrollbar must exist when the regular scrollbar exists");let scale = self.inputs.device_pixels_per_css_pixel;let min_scroll_offset = css_point_to_device_point(minimum_scroll_offset(self.source, paintable), scale);diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/overlay.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/overlay.rsindex 96a7baa1e91..37f4f3f405e 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/overlay.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/overlay.rs@@ -49,7 +49,7 @@ pub(crate) fn paint_overlay<O: Observer>(recorder: &mut PaintRecorder<'_, O>, palet scroll_node_index = own_scroll_node_index;for direction in [ScrollDirection::Vertical, ScrollDirection::Horizontal] {let enlarged = scrollbar_is_enlarged(recorder.source, paintable, direction);- let Some(scrollbar) = chrome_geometry.compute_scrollbar_data(paintable, direction, enlarged, None) else {+ let Some(scrollbar) = chrome_geometry.compute_scrollbar_data(paintable, direction, enlarged) else {continue;};recorder.record_compositor_scrollbar_painted_by_display_list(diff --git a/Tests/LibWeb/Text/expected/UIEvents/scrollbar-drag-driven-by-compositor.txt b/Tests/LibWeb/Text/expected/UIEvents/scrollbar-drag-driven-by-compositor.txtindex 67ac93b974e..e0edcdc853f 100644--- a/Tests/LibWeb/Text/expected/UIEvents/scrollbar-drag-driven-by-compositor.txt+++ b/Tests/LibWeb/Text/expected/UIEvents/scrollbar-drag-driven-by-compositor.txt@@ -16,4 +16,4 @@#5 web-content: finished-handledpointerdown reached the scroller: truescrollTop after the drag: 900-scrolled by an ordinary drag afterwards: true+scrolled by another drag afterwards: truediff --git a/Tests/LibWeb/Text/expected/hit_testing/scrollbar-hit-after-display-list-invalidation.txt b/Tests/LibWeb/Text/expected/hit_testing/scrollbar-hit-after-display-list-invalidation.txtindex 78dbda7232a..189ac13e060 100644--- a/Tests/LibWeb/Text/expected/hit_testing/scrollbar-hit-after-display-list-invalidation.txt+++ b/Tests/LibWeb/Text/expected/hit_testing/scrollbar-hit-after-display-list-invalidation.txt@@ -1 +1 @@-scrolled after scrollbar click: true+scrollbar hit after invalidation: truediff --git a/Tests/LibWeb/Text/input/UIEvents/pointer-events-none-scrollbar.html b/Tests/LibWeb/Text/input/UIEvents/pointer-events-none-scrollbar.htmlindex 0f9b53de060..55a1c0c6f5f 100644--- a/Tests/LibWeb/Text/input/UIEvents/pointer-events-none-scrollbar.html+++ b/Tests/LibWeb/Text/input/UIEvents/pointer-events-none-scrollbar.html@@ -22,12 +22,16 @@ body {</div><script src="../include.js"></script><script>- test(() => {+ promiseTest(async () => {+ await animationFrame();+ await animationFrame();+// Move over the scrollbar area, then click on it. With pointer-events: none,// this should not crash and should not scroll.- internals.mouseMove(147, 50);- internals.mouseDown(147, 50);- internals.mouseUp(147, 50);+ await internals.mouseEventThroughUIProcess("mousemove", 147, 50);+ await internals.mouseEventThroughUIProcess("mousedown", 147, 50);+ await internals.mouseEventThroughUIProcess("mouseup", 147, 50);+ await animationFrame();println(`scrollTop after click on scrollbar: ${scrollable.scrollTop}`);// Wheel events should also not scroll the element.diff --git a/Tests/LibWeb/Text/input/UIEvents/scrollbar-capture-removed-during-drag.html b/Tests/LibWeb/Text/input/UIEvents/scrollbar-capture-removed-during-drag.htmlindex 2ea57b4abee..00b30707f53 100644--- a/Tests/LibWeb/Text/input/UIEvents/scrollbar-capture-removed-during-drag.html+++ b/Tests/LibWeb/Text/input/UIEvents/scrollbar-capture-removed-during-drag.html@@ -21,23 +21,33 @@ body {</div><script src="../include.js"></script><script>- test(() => {+ promiseTest(async () => {+ await animationFrame();+ await animationFrame();++ // The scrollbar goes away while it is dragged.scrollable.addEventListener("pointerdown", () => {scrollable.style.overflowX = "hidden";}, { once: true });- internals.mouseDown(50, 97);- internals.mouseMove(80, 97);- internals.mouseUp(80, 97);+ await internals.mouseEventThroughUIProcess("mousedown", 50, 97);+ await animationFrame();+ await internals.mouseEventThroughUIProcess("mousemove", 80, 97, { buttons: 1 });+ await internals.mouseEventThroughUIProcess("mouseup", 80, 97);+ // The scroller goes away while its scrollbar is dragged.scrollable.style.overflowX = "scroll";- internals.mouseDown(50, 97);- internals.mouseMove(80, 50);+ await animationFrame();+ await animationFrame();+ await internals.mouseEventThroughUIProcess("mousedown", 50, 97);+ await internals.mouseEventThroughUIProcess("mousemove", 80, 50, { buttons: 1 });scrollable.addEventListener("mouseover", () => {scrollable.remove();}, { once: true });- internals.mouseMove(80, 97);- internals.mouseUp(80, 97);+ await internals.mouseEventThroughUIProcess("mousemove", 80, 97, { buttons: 1 });+ await animationFrame();+ await internals.mouseEventThroughUIProcess("mousemove", 90, 97, { buttons: 1 });+ await internals.mouseEventThroughUIProcess("mouseup", 90, 97);println("PASS");});diff --git a/Tests/LibWeb/Text/input/UIEvents/scrollbar-drag-driven-by-compositor.html b/Tests/LibWeb/Text/input/UIEvents/scrollbar-drag-driven-by-compositor.htmlindex 5d506bd2b7e..cb40de97dae 100644--- a/Tests/LibWeb/Text/input/UIEvents/scrollbar-drag-driven-by-compositor.html+++ b/Tests/LibWeb/Text/input/UIEvents/scrollbar-drag-driven-by-compositor.html@@ -39,12 +39,14 @@ body {println(`pointerdown reached the scroller: ${pointerDownCount === 1}`);println(`scrollTop after the drag: ${scroller.scrollTop}`);- // The scrollbar takes an ordinary drag again once the compositor's has ended.+ // The scrollbar takes another drag once the first one has ended.scroller.scrollTop = 0;- internals.mouseDown(147, 5);- internals.mouseMove(147, 60);- internals.mouseUp(147, 60);await animationFrame();- println(`scrolled by an ordinary drag afterwards: ${scroller.scrollTop > 0}`);+ await animationFrame();+ await internals.mouseEventThroughUIProcess("mousedown", 147, 5);+ await internals.mouseEventThroughUIProcess("mousemove", 147, 60, { buttons: 1 });+ await internals.mouseEventThroughUIProcess("mouseup", 147, 60);+ await animationFrame();+ println(`scrolled by another drag afterwards: ${scroller.scrollTop > 0}`);});</script>diff --git a/Tests/LibWeb/Text/input/css/scroll-state-scrolled-absolute-user-scroll.html b/Tests/LibWeb/Text/input/css/scroll-state-scrolled-absolute-user-scroll.htmlindex bcc8ec111ab..9b6c7b583fe 100644--- a/Tests/LibWeb/Text/input/css/scroll-state-scrolled-absolute-user-scroll.html+++ b/Tests/LibWeb/Text/input/css/scroll-state-scrolled-absolute-user-scroll.html@@ -32,10 +32,10 @@await animationFrame();// Dragging the scrollbar thumb is an absolute scroll, so it does not set a scroll direction.- await scrollSettled(scroller, () => {- internals.mouseDown(rect.right - 5, rect.top + 10);- internals.mouseMove(rect.right - 5, rect.top + 60);- internals.mouseUp(rect.right - 5, rect.top + 60);+ await scrollSettled(scroller, async () => {+ await internals.mouseEventThroughUIProcess("mousedown", rect.right - 5, rect.top + 10);+ await internals.mouseEventThroughUIProcess("mousemove", rect.right - 5, rect.top + 60, { buttons: 1 });+ await internals.mouseEventThroughUIProcess("mouseup", rect.right - 5, rect.top + 60);});await animationFrame();await animationFrame();@@ -48,11 +48,11 @@println(`After a wheel scroll up: scrolled=${scrolled()}`);// Dragging the thumb down again keeps the direction of the wheel scroll.- await scrollSettled(scroller, () => {+ await scrollSettled(scroller, async () => {const thumbTop = rect.top + 10 + (scroller.scrollTop / scroller.scrollHeight) * rect.height;- internals.mouseDown(rect.right - 5, thumbTop);- internals.mouseMove(rect.right - 5, thumbTop + 50);- internals.mouseUp(rect.right - 5, thumbTop + 50);+ await internals.mouseEventThroughUIProcess("mousedown", rect.right - 5, thumbTop);+ await internals.mouseEventThroughUIProcess("mousemove", rect.right - 5, thumbTop + 50, { buttons: 1 });+ await internals.mouseEventThroughUIProcess("mouseup", rect.right - 5, thumbTop + 50);});await animationFrame();await animationFrame();diff --git a/Tests/LibWeb/Text/input/hit_testing/scrollbar-hit-after-display-list-invalidation.html b/Tests/LibWeb/Text/input/hit_testing/scrollbar-hit-after-display-list-invalidation.htmlindex 86406d20c06..038da32f547 100644--- a/Tests/LibWeb/Text/input/hit_testing/scrollbar-hit-after-display-list-invalidation.html+++ b/Tests/LibWeb/Text/input/hit_testing/scrollbar-hit-after-display-list-invalidation.html@@ -23,8 +23,6 @@document.body.offsetHeight;scrollable.style.borderLeft = "1px solid transparent";- internals.mouseDown(97, 90);- internals.mouseUp(97, 90);- println(`scrolled after scrollbar click: ${scrollable.scrollTop > 0}`);+ println(`scrollbar hit after invalidation: ${document.elementFromPoint(97, 90) === scrollable}`);});</script>diff --git a/Tests/LibWeb/Text/input/hit_testing/scrollbar-in-nested-scrollable.html b/Tests/LibWeb/Text/input/hit_testing/scrollbar-in-nested-scrollable.htmlindex 6a8ae6829a8..bb8dc3ccbed 100644--- a/Tests/LibWeb/Text/input/hit_testing/scrollbar-in-nested-scrollable.html+++ b/Tests/LibWeb/Text/input/hit_testing/scrollbar-in-nested-scrollable.html@@ -43,15 +43,16 @@ body {<script>outer.scrollTop = 300;- asyncTest(done => {- // Move the cursor above the inner scrollbar gutter and click to scroll down.- internals.mouseMove(147, 50);- internals.mouseDown(147, 80);- internals.mouseUp(147, 80);+ promiseTest(async () => {+ await animationFrame();+ await animationFrame();- requestAnimationFrame(() => {- println(`inner scrolled: ${inner.scrollTop > 0}`);- done();+ // Move the cursor over the inner scrollbar, and press its gutter below the thumb to page down.+ await scrollSettled(inner, async () => {+ await internals.mouseEventThroughUIProcess("mousemove", 147, 50);+ await internals.mouseEventThroughUIProcess("mousedown", 147, 80);+ await internals.mouseEventThroughUIProcess("mouseup", 147, 80);});+ println(`inner scrolled: ${inner.scrollTop > 0}`);});</script>diff --git a/Tests/LibWeb/Text/input/scroll-snap-after-scrollbar-drag.html b/Tests/LibWeb/Text/input/scroll-snap-after-scrollbar-drag.htmlindex fb0eef4ffe5..1a3988bceec 100644--- a/Tests/LibWeb/Text/input/scroll-snap-after-scrollbar-drag.html+++ b/Tests/LibWeb/Text/input/scroll-snap-after-scrollbar-drag.html@@ -33,13 +33,16 @@println(`scroll offset after a down arrow key press: ${scroller.scrollLeft},${scroller.scrollTop}`);// Dragging the scrollbar thumb is an absolute scroll, so it snaps to the position nearest the drop point. The- // drag ends beyond the gutter so that every update along the way clamps to the maximal scroll position.+ // drag ends beyond the gutter so that every update along the way clamps to the maximal scroll position. The+ // press is on the thumb, as a press beside it pages instead.const rect = scroller.getBoundingClientRect();- await scrollSettled(scroller, () => {- internals.mouseDown(rect.right - 5, rect.bottom - 5);- internals.mouseMove(rect.right - 5, rect.bottom + 200);- internals.mouseUp(rect.right - 5, rect.bottom + 200);- });+ const dragThumbToTheEnd = async () => {+ const thumbY = rect.top + 10 + (scroller.scrollTop / scroller.scrollHeight) * rect.height;+ await internals.mouseEventThroughUIProcess("mousedown", rect.right - 5, thumbY);+ await internals.mouseEventThroughUIProcess("mousemove", rect.right - 5, rect.bottom + 200, { buttons: 1 });+ await internals.mouseEventThroughUIProcess("mouseup", rect.right - 5, rect.bottom + 200);+ };+ await scrollSettled(scroller, dragThumbToTheEnd);println(`scroll offset after dragging the scrollbar to the end: ${scroller.scrollLeft},${scroller.scrollTop}`);scroller.scrollTo({ top: 0, behavior: "instant" });@@ -55,11 +58,7 @@// The next drag reports no gesture phase of its own, so the momentum rules of the gesture before it do not// apply to it.- await scrollSettled(scroller, () => {- internals.mouseDown(rect.right - 5, rect.bottom - 5);- internals.mouseMove(rect.right - 5, rect.bottom + 200);- internals.mouseUp(rect.right - 5, rect.bottom + 200);- });+ await scrollSettled(scroller, dragThumbToTheEnd);println(`scroll offset after dragging the scrollbar to the end again: ${scroller.scrollLeft},${scroller.scrollTop}`);});</script>