Skip to content

Truly independent web browser

LibWeb+Compositor: Count scrolls for input the same on both sides

Andreas Klingb6b1909def58
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
index 56a9f4dd3b9..2a0e9555713 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
@@ -229,6 +229,7 @@ Optional<AsyncScrollOffset> AsyncScrollTree::apply_scroll_delta(Compositing::Spa
.visual_viewport_scale = {},
.applied_scroll_request_id = 0,
.user_input_scroll_count = 0,
+ .context_user_input_scroll_count = 0,
};
}
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
index 015ab333381..2422efa0f57 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
@@ -45,12 +45,16 @@ struct AsyncScrollOffset {
u64 applied_scroll_request_id { 0 };
// How many times the compositor had scrolled the box for user input of its own when it reported this.
u64 user_input_scroll_count { 0 };
+ // How many times the compositor had scrolled any box of the context for user input of its own when it reported
+ // this. Not every such scroll is reported, as one the next input turns back moves no box.
+ u64 context_user_input_scroll_count { 0 };
void merge_later_scroll(AsyncScrollOffset const& later)
{
compositor_scroll_offset = later.compositor_scroll_offset;
applied_scroll_request_id = later.applied_scroll_request_id;
user_input_scroll_count = later.user_input_scroll_count;
+ context_user_input_scroll_count = later.context_user_input_scroll_count;
if (later.visual_viewport_scale.has_value())
visual_viewport_scale = later.visual_viewport_scale;
unadopted_scroll_delta.translate_by(later.unadopted_scroll_delta);
diff --git a/Libraries/LibCompositing/Types.cpp b/Libraries/LibCompositing/Types.cpp
index 2c02444725a..2f2773e576b 100644
--- a/Libraries/LibCompositing/Types.cpp
+++ b/Libraries/LibCompositing/Types.cpp
@@ -43,6 +43,7 @@ ErrorOr<void> encode(Encoder& encoder, Compositing::AsyncScrollOffset const& off
TRY(encoder.encode(offset.visual_viewport_scale));
TRY(encoder.encode(offset.applied_scroll_request_id));
TRY(encoder.encode(offset.user_input_scroll_count));
+ TRY(encoder.encode(offset.context_user_input_scroll_count));
return {};
}
@@ -57,6 +58,7 @@ ErrorOr<Compositing::AsyncScrollOffset> decode(Decoder& decoder)
.visual_viewport_scale = TRY(decoder.decode<Optional<float>>()),
.applied_scroll_request_id = TRY(decoder.decode<u64>()),
.user_input_scroll_count = TRY(decoder.decode<u64>()),
+ .context_user_input_scroll_count = TRY(decoder.decode<u64>()),
};
}
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 221e63ac923..9aec7fcd256 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -5919,6 +5919,7 @@ void LocalNavigable::adopt_pending_async_scroll_offsets(Compositing::AsyncScroll
if (async_scroll_offset.user_input_scroll_count > user_input_scroll_count)
extend_user_scroll_gesture_of(async_scroll_offset.stable_node_id);
user_input_scroll_count = max(user_input_scroll_count, async_scroll_offset.user_input_scroll_count);
+ m_compositor_context_user_input_scroll_count = max(m_compositor_context_user_input_scroll_count, async_scroll_offset.context_user_input_scroll_count);
// What the compositor reported of a box before it applied the last scroll this navigable asked of it describes
// what that scroll replaced. Once it applied it, the compositor has the box's offset.
@@ -6765,6 +6766,7 @@ void LocalNavigable::repaint_after_compositor_process_reconnect()
// A new compositor process has applied none of the scrolls this navigable asked the old one for.
m_scroll_request_states.clear();
m_compositor_user_input_scroll_counts.clear();
+ m_compositor_context_user_input_scroll_count = 0;
if (has_compositor_context()) {
if (auto parent = this->parent()) {
@@ -7415,14 +7417,6 @@ void LocalNavigable::set_scroll_offset_settled_by_layout(Layout::Node& scrolling
(void)Painting::set_scroll_offset(scrolling_box, scroll_offset);
}
-u64 LocalNavigable::compositor_user_input_scroll_count() const
-{
- u64 count = 0;
- for (auto const& entry : m_compositor_user_input_scroll_counts)
- count += entry.value;
- return count;
-}
-
void LocalNavigable::did_change_scroll_offset(Web::AsyncScrollNodeStableID stable_node_id)
{
note_scroll_sequence_moved(stable_node_id);
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index c19546c0e63..04019ea49ec 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -254,7 +254,7 @@ public:
void perform_scroll_of_viewport_scrolling_box(CSSPixelPoint position);
// Every change of a scroll offset here, other than one the compositor made, goes to the compositor as a request.
void did_change_scroll_offset(Web::AsyncScrollNodeStableID);
- u64 compositor_user_input_scroll_count() const;
+ u64 compositor_user_input_scroll_count() const { return m_compositor_context_user_input_scroll_count; }
void set_scroll_offset_settled_by_layout(Layout::Node& scrolling_box, CSSPixelPoint scroll_offset);
// Changes a scrolling box's offset for user input on this thread, which the compositor is asked for as the user's.
bool set_scroll_offset_for_user_input(Layout::Node& scrolling_box, Web::AsyncScrollNodeStableID, CSSPixelPoint);
@@ -724,6 +724,7 @@ private:
Compositing::AsyncScrollOperationID m_last_requested_operation_id { Compositing::first_operation_id_the_main_thread_requests };
// How many times the compositor reported having scrolled each box for its own user input.
HashMap<Web::AsyncScrollNodeStableID, u64> m_compositor_user_input_scroll_counts;
+ u64 m_compositor_context_user_input_scroll_count { 0 };
// Set while this navigable changes an offset it asks for in a request of its own making, or takes the compositor's,
// which it asks for nothing about.
bool m_scroll_offset_changes_need_no_request { false };
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index a4c033cbd12..166a6e3285c 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -765,6 +765,7 @@ ContextState::ContextUpdateResult ContextState::handle_pinch_event(Web::PinchEve
.visual_viewport_scale = transform.matrix[0, 0],
.applied_scroll_request_id = 0,
.user_input_scroll_count = 0,
+ .context_user_input_scroll_count = 0,
};
store_pending_async_scroll_offsets({ &scroll_offset, 1 });
}
@@ -1003,14 +1004,7 @@ ContextState::NodeScrollByWheelDelta ContextState::scroll_node_by_wheel_delta(Co
void ContextState::note_user_input_scrolled(Web::AsyncScrollNodeStableID stable_node_id)
{
m_user_input_scroll_counts.ensure(stable_node_id)++;
-}
-
-u64 ContextState::user_input_scroll_count() const
-{
- u64 count = 0;
- for (auto const& entry : m_user_input_scroll_counts)
- count += entry.value;
- return count;
+ m_context_user_input_scroll_count++;
}
Optional<Gfx::Orientation> ContextState::axis_held_by_scrollbar_of(Compositing::SpatialNodeIndex scroll_node_index) const
@@ -1064,6 +1058,7 @@ Optional<PendingFrame> ContextState::apply_scroll_requests(ReadonlySpan<Composit
.visual_viewport_scale = {},
.applied_scroll_request_id = 0,
.user_input_scroll_count = 0,
+ .context_user_input_scroll_count = 0,
});
};
@@ -1244,6 +1239,7 @@ void ContextState::scroll_visual_viewport_position_in_page(Compositing::SpatialN
.visual_viewport_scale = scale,
.applied_scroll_request_id = 0,
.user_input_scroll_count = 0,
+ .context_user_input_scroll_count = 0,
});
}
@@ -1278,6 +1274,7 @@ bool ContextState::apply_visual_viewport_scroll_request(Compositing::ScrollReque
.visual_viewport_scale = transform.matrix[0, 0],
.applied_scroll_request_id = 0,
.user_input_scroll_count = 0,
+ .context_user_input_scroll_count = 0,
});
return new_scroll_offset != old_scroll_offset;
}
@@ -1404,6 +1401,7 @@ Optional<Gfx::IntRect> ContextState::advance_smooth_scroll_animations(MonotonicT
.visual_viewport_scale = {},
.applied_scroll_request_id = 0,
.user_input_scroll_count = 0,
+ .context_user_input_scroll_count = 0,
});
changed_scroll_offset = true;
if (m_async_scroll_tree.scroll_node_is_viewport(*scroll_node_index))
@@ -2211,6 +2209,7 @@ Optional<ContextState::VisualViewportScrollDelta> ContextState::apply_visual_vie
.visual_viewport_scale = scale,
.applied_scroll_request_id = 0,
.user_input_scroll_count = 0,
+ .context_user_input_scroll_count = 0,
},
.consumed_delta = consumed_delta,
};
@@ -2267,6 +2266,7 @@ Optional<Gfx::FloatPoint> ContextState::keep_scroll_offsets_of_known_nodes(HashM
.visual_viewport_scale = {},
.applied_scroll_request_id = 0,
.user_input_scroll_count = 0,
+ .context_user_input_scroll_count = 0,
});
}
}
@@ -2288,6 +2288,7 @@ void ContextState::store_pending_async_scroll_offsets(
for (auto scroll_offset : scroll_offsets) {
scroll_offset.applied_scroll_request_id = m_applied_scroll_request_ids.get(scroll_offset.stable_node_id).value_or(0);
scroll_offset.user_input_scroll_count = m_user_input_scroll_counts.get(scroll_offset.stable_node_id).value_or(0);
+ scroll_offset.context_user_input_scroll_count = m_context_user_input_scroll_count;
stamped_scroll_offsets.unchecked_append(scroll_offset);
}
m_async_scroll_update_outbox.record_scroll_offsets(stamped_scroll_offsets);
@@ -2563,6 +2564,7 @@ Optional<PendingFrame> ContextState::apply_scrollbar_drag(ScrollbarController::D
.visual_viewport_scale = {},
.applied_scroll_request_id = 0,
.user_input_scroll_count = 0,
+ .context_user_input_scroll_count = 0,
});
store_pending_async_scroll_offsets(scroll_offsets);
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index c53f958887a..d4203676af6 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -249,7 +249,7 @@ public:
// Whether this context's page may cancel the ctrl+wheel event of a pinch at the position, or has yet to tell.
bool page_may_cancel_pinch_at(Gfx::FloatPoint position);
bool pinch_gesture_was_let_through() const { return m_pinch_gesture_was_let_through; }
- u64 user_input_scroll_count() const;
+ u64 user_input_scroll_count() const { return m_context_user_input_scroll_count; }
void set_pinch_gesture_was_let_through(bool was_let_through) { m_pinch_gesture_was_let_through = was_let_through; }
bool may_hand_first_wheel_steps_to_nested_contexts() const;
@@ -490,6 +490,7 @@ private:
HashMap<Web::AsyncScrollNodeStableID, u64> m_applied_scroll_request_ids;
// How many times this context scrolled each box for user input of its own, which the reports are marked with too.
HashMap<Web::AsyncScrollNodeStableID, u64> m_user_input_scroll_counts;
+ u64 m_context_user_input_scroll_count { 0 };
// The boxes the last frame brought, whose offsets came from that frame's snapshot.
HashTable<Web::AsyncScrollNodeStableID> m_scroll_nodes_seeded_by_last_frame;
// Whether this context has scrolled boxes to offsets that WebContent's last frame does not have them at.
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/key-with-nothing-to-scroll-after-input-that-moved-no-box.txt b/Tests/LibWeb/Text/expected/async-scrolling/key-with-nothing-to-scroll-after-input-that-moved-no-box.txt
index 37d91bf2456..79766a510eb 100644
--- a/Tests/LibWeb/Text/expected/async-scrolling/key-with-nothing-to-scroll-after-input-that-moved-no-box.txt
+++ b/Tests/LibWeb/Text/expected/async-scrolling/key-with-nothing-to-scroll-after-input-that-moved-no-box.txt
@@ -1,5 +1,5 @@
box offset: 0
-beside the task, the compositor scrolled past the first Down: false
+beside the task, the compositor scrolled past the first Down: true
keys the page heard of: ArrowUp, ArrowDown, ArrowDown
-compositor offset once settled: 100
-main thread offset: 100
+compositor offset once settled: 200
+main thread offset: 200