Skip to content

Truly independent web browser

LibWeb+Compositor: Let overlay scrollbars that faded out take no input

Andreas Kling1637ecf02dfc
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
index 53f54d92b0f..02ebd3452c8 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
@@ -849,6 +849,17 @@ void CompositorConnection::rendering_opportunity(Web::CompositorContextId contex
}
}
+void CompositorConnection::overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> visibilities)
+{
+ // Each scroller belongs to the active document of one of our navigables, which takes its scrollbar's visibility.
+ for (auto const& visibility : visibilities) {
+ for (auto& navigable : Web::HTML::all_local_navigables()) {
+ if (navigable->set_overlay_scrollbar_hidden(visibility.scroller_stable_node_id, visibility.vertical, visibility.hidden))
+ break;
+ }
+ }
+}
+
void CompositorConnection::placeholder_canvas_committed(Compositing::CanvasId canvas_id, Gfx::IntSize size, bool origin_clean)
{
Web::HTML::HTMLCanvasElement::placeholder_frame_committed(canvas_id, size, origin_clean);
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.h b/Libraries/LibWeb/Compositor/CompositorConnection.h
index 2e0114f4ec8..9f591ed77f7 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.h
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h
@@ -119,6 +119,7 @@ private:
virtual void did_fail_screenshot(Compositing::ScreenshotRequestId) override;
virtual void did_lose_compositor() override;
virtual void placeholder_canvas_committed(Compositing::CanvasId, Gfx::IntSize, bool origin_clean) override;
+ virtual void overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility>) override;
bool can_send_message_to_compositor() const;
void merge_async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates);
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 98727ac9764..ce29cb20e70 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -4990,6 +4990,30 @@ static Layout::Node* committed_scrolling_box_for_async_scroll_node(DOM::Document
return scrolling_box;
}
+// The compositor fades overlay scrollbars, and says which have faded out, so that hit testing passes them by.
+bool LocalNavigable::set_overlay_scrollbar_hidden(Web::AsyncScrollNodeStableID stable_node_id, bool vertical, bool hidden)
+{
+ auto document = active_document();
+ if (!document)
+ return false;
+ // NB: The compositor can report this while layout is out of date, so this reads the committed layout.
+ Layout::Node* scrolling_box = nullptr;
+ if (auto pseudo_element = pseudo_element_from_async_scroll_node_stable_id(stable_node_id); pseudo_element.has_value()) {
+ Layout::ForcedReadScope read { *document };
+ if (auto* element = element_for_async_scroll_node_stable_id(*document, stable_node_id))
+ scrolling_box = element->pseudo_element_unsafe_layout_node(read, *pseudo_element);
+ if (scrolling_box && !Painting::has_committed_box(*scrolling_box))
+ scrolling_box = nullptr;
+ } else {
+ scrolling_box = committed_scrolling_box_for_async_scroll_node(*document, stable_node_id);
+ }
+ if (!scrolling_box)
+ return false;
+ auto direction = vertical ? Layout::RustFFI::ScrollDirection::Vertical : Layout::RustFFI::ScrollDirection::Horizontal;
+ Layout::RustFFI::render_state_set_scrollbar_hidden(scrolling_box->document_host(), Painting::committed_row_slot(*scrolling_box), direction, hidden);
+ return true;
+}
+
// https://drafts.csswg.org/css-conditional-5/#scrolled
// A relative scroll, made by the user or by a relative scrolling API, sets the direction scroll-state(scrolled) reads.
// An absolute one leaves it as it is.
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index 928edeb28c8..8c03990ff1d 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -411,6 +411,8 @@ public:
void queue_scrollend_event_after_user_scroll(GC::Ref<DOM::EventTarget>, Optional<Web::AsyncScrollNodeStableID>, Optional<CSSPixelPoint> scroll_offset_before_scroll = {}, SnapPositionSelection = SnapPositionSelection::AtGestureEnd);
void note_user_scroll_input_intent(Compositing::SnapSelectionStrategy::Type);
RefPtr<Painting::Scrollbar> scrollbar_dragged_by_compositor(Layout::BegunRead const& read, Web::ScrollbarDraggedByCompositor const&);
+ // Returns false if the scroller is not in this navigable's active document.
+ bool set_overlay_scrollbar_hidden(Web::AsyncScrollNodeStableID, bool vertical, bool hidden);
void note_user_scroll_gesture_phase(Web::ScrollGesturePhase);
void did_handle_wheel_event();
void defer_user_scroll_settlement();
diff --git a/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs b/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs
index d8f8fbd9e9b..2aa2b786b8c 100644
--- a/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs
+++ b/Libraries/LibWeb/Rust/src/painting/chrome_geometry.rs
@@ -247,6 +247,14 @@ pub(crate) fn scrollbar_is_enlarged(arena: &impl PaintRead, slot: NodeSlotId, di
arena.paintable_data(slot).has_flag(flag)
}
+pub(crate) fn scrollbar_is_hidden(arena: &impl PaintRead, slot: NodeSlotId, direction: ScrollDirection) -> bool {
+ let flag = match direction {
+ ScrollDirection::Horizontal => PaintableFlag::HorizontalScrollbarHidden,
+ ScrollDirection::Vertical => PaintableFlag::VerticalScrollbarHidden,
+ };
+ arena.paintable_data(slot).has_flag(flag)
+}
+
pub(crate) struct ChromeGeometry<'a, Arena: PaintRead> {
pub(crate) arena: &'a Arena,
pub(crate) metrics: FfiChromeMetrics,
diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/query.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/query.rs
index ab35e6fda66..54e8ad69c92 100644
--- a/Libraries/LibWeb/Rust/src/painting/hit_test/query.rs
+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/query.rs
@@ -5,7 +5,7 @@
*/
use super::*;
-use crate::painting::chrome_geometry::{ChromeGeometry, scrollbar_is_enlarged};
+use crate::painting::chrome_geometry::{ChromeGeometry, scrollbar_is_enlarged, scrollbar_is_hidden};
use crate::painting::ffi::ScrollDirection;
use crate::painting::host::FfiHitTestQueryCallbacks;
use crate::painting::paint_read::PaintRead;
@@ -139,9 +139,11 @@ impl HitTestList {
} else {
ScrollDirection::Vertical
};
- chrome_geometry
- .absolute_scrollbar_rect(node, direction, scrollbar_is_enlarged(rows, node, direction))
- .is_some_and(|rect| rect.contains_point(local_point))
+ // An overlay scrollbar that has faded out takes no pointer input, as in Chromium.
+ !scrollbar_is_hidden(rows, node, direction)
+ && chrome_geometry
+ .absolute_scrollbar_rect(node, direction, scrollbar_is_enlarged(rows, node, direction))
+ .is_some_and(|rect| rect.contains_point(local_point))
}
_ => false,
}
diff --git a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs b/Libraries/LibWeb/Rust/src/painting/paint_changes.rs
index 1db6129aca7..6ae968efa18 100644
--- a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paint_changes.rs
@@ -70,6 +70,12 @@ pub(crate) enum PaintChange {
direction: ScrollDirection,
enlarged: bool,
},
+ /// Whether the overlay scrollbar of the row in `direction` has faded out, so that it takes no pointer input.
+ SetScrollbarHidden {
+ node: NodeSlotId,
+ direction: ScrollDirection,
+ hidden: bool,
+ },
/// The images the row's background, mask and border image layers paint.
SetLayerImagePaintFacts {
node: NodeSlotId,
@@ -181,6 +187,25 @@ impl PaintChange {
rows.paintable_data_mut(node).set_flag(flag, enlarged);
rows.push_paint_damage(node, PaintDamage::DRAW_OVERLAY | PaintDamage::HIT_OVERLAY);
}
+ Self::SetScrollbarHidden {
+ node,
+ direction,
+ hidden,
+ } => {
+ let mut rows = arena.paintable_rows_mut();
+ if !rows.paintable_row_is_populated(node) {
+ return;
+ }
+ let flag = match direction {
+ ScrollDirection::Horizontal => PaintableFlag::HorizontalScrollbarHidden,
+ ScrollDirection::Vertical => PaintableFlag::VerticalScrollbarHidden,
+ };
+ if rows.paintable_data(node).has_flag(flag) == hidden {
+ return;
+ }
+ rows.paintable_data_mut(node).set_flag(flag, hidden);
+ rows.push_paint_damage(node, PaintDamage::HIT_OVERLAY);
+ }
Self::SetLayerImagePaintFacts { node, entries } => {
arena.set_layer_image_paint_facts(node, entries);
}
@@ -365,6 +390,21 @@ pub extern "C" fn render_state_set_scrollbar_enlarged(
queue(host, change);
}
+#[unsafe(no_mangle)]
+pub extern "C" fn render_state_set_scrollbar_hidden(
+ host: &DocumentHost,
+ node: NodeSlotId,
+ direction: ScrollDirection,
+ hidden: bool,
+) {
+ let change = PaintChange::SetScrollbarHidden {
+ node,
+ direction,
+ hidden,
+ };
+ queue(host, change);
+}
+
/// # Safety
///
/// `host` must be a live document host, on the document's thread, and `entries` must point at `count` readable
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs b/Libraries/LibWeb/Rust/src/painting/paintable_data.rs
index 6bf65027a59..19911306ec0 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_data.rs
@@ -16,6 +16,8 @@ pub enum PaintableFlag {
HasNonInvertibleCssTransform = 1 << 0,
HorizontalScrollbarEnlarged = 1 << 1,
VerticalScrollbarEnlarged = 1 << 2,
+ HorizontalScrollbarHidden = 1 << 3,
+ VerticalScrollbarHidden = 1 << 4,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
diff --git a/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.cpp b/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.cpp
index 0051ed326ae..f6da8be8c52 100644
--- a/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.cpp
+++ b/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.cpp
@@ -63,4 +63,23 @@ ErrorOr<Web::ScrollbarDraggedByCompositor> decode(Decoder& decoder)
};
}
+template<>
+ErrorOr<void> encode(Encoder& encoder, Web::OverlayScrollbarVisibility const& visibility)
+{
+ TRY(encoder.encode(visibility.scroller_stable_node_id));
+ TRY(encoder.encode(visibility.vertical));
+ TRY(encoder.encode(visibility.hidden));
+ return {};
+}
+
+template<>
+ErrorOr<Web::OverlayScrollbarVisibility> decode(Decoder& decoder)
+{
+ return Web::OverlayScrollbarVisibility {
+ .scroller_stable_node_id = TRY(decoder.decode<Web::AsyncScrollNodeStableID>()),
+ .vertical = TRY(decoder.decode<bool>()),
+ .hidden = TRY(decoder.decode<bool>()),
+ };
+}
+
}
diff --git a/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.h b/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.h
index 0fff5590dc2..df09d5a98b8 100644
--- a/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.h
+++ b/Libraries/LibWebCommon/Page/AsyncScrollNodeStableID.h
@@ -48,6 +48,15 @@ struct ScrollbarDraggedByCompositor {
bool operator==(ScrollbarDraggedByCompositor const&) const = default;
};
+// Whether an overlay scrollbar that the compositor fades has faded out, so that it takes no pointer input.
+struct OverlayScrollbarVisibility {
+ AsyncScrollNodeStableID scroller_stable_node_id;
+ bool vertical { false };
+ bool hidden { false };
+
+ bool operator==(OverlayScrollbarVisibility const&) const = default;
+};
+
}
template<>
@@ -76,4 +85,9 @@ WEBCOMMON_API ErrorOr<void> encode(Encoder&, Web::ScrollbarDraggedByCompositor c
template<>
WEBCOMMON_API ErrorOr<Web::ScrollbarDraggedByCompositor> decode(Decoder&);
+template<>
+WEBCOMMON_API ErrorOr<void> encode(Encoder&, Web::OverlayScrollbarVisibility const&);
+template<>
+WEBCOMMON_API ErrorOr<Web::OverlayScrollbarVisibility> decode(Decoder&);
+
}
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index 3f9e7e4734b..23b8aab8778 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -65,6 +65,7 @@ public:
virtual void pointer_moved(Web::CompositorContextId, Web::DevicePixelPoint, u32 /* buttons */, bool /* scrolled_since_frame */, u64 /* input_event_id */) { }
virtual void pointer_left(Web::CompositorContextId, u64 /* input_event_id */) { }
virtual void async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates const&) = 0;
+ virtual void overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> const&) { }
virtual void create_video_edge(Media::VideoSinkHandle) = 0;
virtual void release_video_edge(Media::VideoSinkHandle) = 0;
virtual void video_sink_presented_frame(Media::VideoSinkHandle, RefPtr<Media::VideoFrame>, Media::DisplayingVideoSinkFrameCounts) { }
diff --git a/Services/Compositor/CompositorWebContentClient.ipc b/Services/Compositor/CompositorWebContentClient.ipc
index 045b64780fe..341dc044c2a 100644
--- a/Services/Compositor/CompositorWebContentClient.ipc
+++ b/Services/Compositor/CompositorWebContentClient.ipc
@@ -10,6 +10,7 @@ endpoint CompositorWebContentClient
request_rendering_update() =|
rendering_opportunity(Web::CompositorContextId context_id, i64 frame_time_nanoseconds, double frame_interval_milliseconds) =|
async_scroll_updates(Web::CompositorContextId context_id, Compositing::PendingAsyncScrollUpdates updates) =|
+ overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> visibilities) =|
did_complete_screenshot(Compositing::ScreenshotRequestId request_id) =|
did_fail_screenshot(Compositing::ScreenshotRequestId request_id) =|
did_lose_compositor() =|
diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cpp
index 33526f65a03..eee03995f84 100644
--- a/Services/Compositor/ConnectionFromWebContent.cpp
+++ b/Services/Compositor/ConnectionFromWebContent.cpp
@@ -151,6 +151,11 @@ void ConnectionFromWebContent::async_scroll_updates(Web::CompositorContextId con
async_async_scroll_updates(context_id, updates);
}
+void ConnectionFromWebContent::overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> const& visibilities)
+{
+ async_overlay_scrollbar_visibilities_changed(visibilities);
+}
+
void ConnectionFromWebContent::dispatch_mouse_event_to_web_content(u64 page_id, Web::MouseEvent const& event)
{
async_mouse_event(page_id, event);
diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.h
index f0df8d81f38..23d15281eb6 100644
--- a/Services/Compositor/ConnectionFromWebContent.h
+++ b/Services/Compositor/ConnectionFromWebContent.h
@@ -100,6 +100,7 @@ private:
virtual void pointer_moved(Web::CompositorContextId, Web::DevicePixelPoint, u32 buttons, bool scrolled_since_frame, u64 input_event_id) override;
virtual void pointer_left(Web::CompositorContextId, u64 input_event_id) override;
virtual void async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates const&) override;
+ virtual void overlay_scrollbar_visibilities_changed(Vector<Web::OverlayScrollbarVisibility> const&) override;
virtual void create_video_edge(Media::VideoSinkHandle) override;
virtual void release_video_edge(Media::VideoSinkHandle) override;
virtual void video_sink_presented_frame(Media::VideoSinkHandle, RefPtr<Media::VideoFrame>, Media::DisplayingVideoSinkFrameCounts) override;
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index 537a27bf32e..f690b37dfe5 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -1612,6 +1612,7 @@ Gfx::IntRect ContextState::update_scrollbar_visibility()
auto const* visual_context_tree = m_scene.visual_context_tree().has_value() ? &m_scene.visual_context_tree_for_compositing() : nullptr;
auto now = MonotonicTime::now();
auto damage_rect = m_scrollbar_controller.update_visibility(visual_context_tree, presented_scroll_state_snapshot, now);
+ report_scrollbar_visibility_changes();
// A hovered scrollbar starts to grow here, which needs display ticks before anything else asks for a frame.
if (m_request_animation_frames && m_scrollbar_controller.fades_need_frame(now))
@@ -1634,6 +1635,15 @@ Gfx::IntRect ContextState::update_scrollbar_visibility()
return damage_rect;
}
+// 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.
+void ContextState::report_scrollbar_visibility_changes()
+{
+ auto changes = m_scrollbar_controller.take_visibility_changes();
+ if (!changes.is_empty())
+ m_web_content_client.overlay_scrollbar_visibilities_changed(changes);
+}
+
Optional<PendingFrame> ContextState::advance_scrollbar_fades(MonotonicTime frame_time)
{
if (!m_scene.visual_context_tree().has_value())
@@ -1641,6 +1651,7 @@ Optional<PendingFrame> ContextState::advance_scrollbar_fades(MonotonicTime frame
auto stretched_scroll_state_snapshot = scroll_state_snapshot_stretched_by_elastic_overscrolls();
auto const& presented_scroll_state_snapshot = stretched_scroll_state_snapshot.has_value() ? *stretched_scroll_state_snapshot : m_scroll_state_snapshot;
auto damage_rect = m_scrollbar_controller.advance_fades(m_scene.visual_context_tree_for_compositing(), presented_scroll_state_snapshot, frame_time);
+ report_scrollbar_visibility_changes();
auto viewport_rect = m_presenter.viewport_rect_for_ui_overlay();
if (damage_rect.is_empty() || !viewport_rect.has_value())
return {};
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index 62b35264a8d..59602fec272 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -340,6 +340,7 @@ private:
ContextPresenter::FrameContent frame_content(Compositing::ScrollStateSnapshot const& presented_scroll_state_snapshot, CompositedContextResolver const*) const;
Gfx::IntRect damage_rect_of_blinking_carets();
Gfx::IntRect update_scrollbar_visibility();
+ void report_scrollbar_visibility_changes();
CompositorStateWebContentClient& m_web_content_client;
Web::CompositorContextId m_context_id;
diff --git a/Services/Compositor/ScrollbarController.cpp b/Services/Compositor/ScrollbarController.cpp
index 72c39b4b129..349c215d166 100644
--- a/Services/Compositor/ScrollbarController.cpp
+++ b/Services/Compositor/ScrollbarController.cpp
@@ -198,7 +198,8 @@ Optional<ScrollbarController::Drag> ScrollbarController::begin_drag(Compositing:
auto scrollbar_index = hit_test_scrollbar_painted_by_compositor(async_scroll_tree, scroll_state_snapshot, position);
if (!scrollbar_index.has_value())
scrollbar_index = hit_test_scrollbar_painted_by_display_list(async_scroll_tree, visual_context_tree, scroll_state_snapshot, position);
- if (!scrollbar_index.has_value())
+ // A scrollbar that has faded out takes no press, as in Chromium.
+ if (!scrollbar_index.has_value() || opacity(*scrollbar_index) <= 0)
return {};
auto const& scrollbar = m_scrollbars[*scrollbar_index];
@@ -365,6 +366,21 @@ Optional<MonotonicTime> ScrollbarController::next_fade_out_time() const
return next_fade_out_time;
}
+Vector<Web::OverlayScrollbarVisibility> ScrollbarController::take_visibility_changes()
+{
+ Vector<Web::OverlayScrollbarVisibility> changes;
+ for (size_t i = 0; i < m_scrollbars.size(); ++i) {
+ auto const& scrollbar = m_scrollbars[i];
+ auto& visibility = m_visibilities[i];
+ auto hidden = opacity(i) <= 0;
+ if (!scrollbar.scroller_stable_node_id.has_value() || hidden == visibility.reported_hidden)
+ continue;
+ visibility.reported_hidden = hidden;
+ changes.append({ .scroller_stable_node_id = *scrollbar.scroller_stable_node_id, .vertical = scrollbar.vertical, .hidden = hidden });
+ }
+ return changes;
+}
+
bool ScrollbarController::fades_need_frame(MonotonicTime now) const
{
for (auto const& visibility : m_visibilities) {
diff --git a/Services/Compositor/ScrollbarController.h b/Services/Compositor/ScrollbarController.h
index 5b4cc7614eb..e37074b3a3e 100644
--- a/Services/Compositor/ScrollbarController.h
+++ b/Services/Compositor/ScrollbarController.h
@@ -76,6 +76,9 @@ public:
Gfx::IntRect update_visibility(Compositing::AccumulatedVisualContextTree const*, Compositing::ScrollStateSnapshot const&, MonotonicTime now);
// When the next scrollbar starts to fade out.
Optional<MonotonicTime> next_fade_out_time() const;
+ // The scrollbars that faded out or were shown again since the last call. The main thread hit tests the scrollbars
+ // too, and passes by the ones that have faded out.
+ Vector<Web::OverlayScrollbarVisibility> take_visibility_changes();
bool fades_need_frame(MonotonicTime now) const;
// Returns the rect in the viewport of the scrollbars whose opacity or geometry changed.
Gfx::IntRect advance_fades(Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot const&, MonotonicTime frame_time);
@@ -111,6 +114,8 @@ private:
Optional<MonotonicTime> fade_out_time;
// How far the scrollbar has grown from its thin geometry to its expanded one.
Compositing::OverlayFade expansion;
+ // Whether the main thread was last told that the scrollbar has faded out.
+ bool reported_hidden { false };
};
bool is_expanded(size_t scrollbar_index) const;
diff --git a/Tests/Compositor/TestScrollbarController.cpp b/Tests/Compositor/TestScrollbarController.cpp
index d5261a6cd76..2af190322d3 100644
--- a/Tests/Compositor/TestScrollbarController.cpp
+++ b/Tests/Compositor/TestScrollbarController.cpp
@@ -10,6 +10,18 @@
#include <LibCompositing/Scrolling/ScrollState.h>
#include <LibTest/TestCase.h>
+// A scroll shows the scrollbars, which only take a press while shown. Scrolling back leaves them where they started.
+static void show_scrollbars_by_scrolling_away_and_back(Compositor::ScrollbarController& controller, Compositing::SpatialNodeIndex scroll_node_index)
+{
+ Compositing::ScrollStateSnapshot scroll_state_snapshot;
+ auto now = MonotonicTime::now();
+ (void)controller.update_visibility(nullptr, scroll_state_snapshot, now);
+ scroll_state_snapshot.set_device_offset_for_index(scroll_node_index, { 1, 1 });
+ (void)controller.update_visibility(nullptr, scroll_state_snapshot, now);
+ scroll_state_snapshot.set_device_offset_for_index(scroll_node_index, { 0, 0 });
+ (void)controller.update_visibility(nullptr, scroll_state_snapshot, now);
+}
+
static Compositor::ScrollbarController::Drag begin_scrollbar_drag(Gfx::Orientation orientation, Gfx::FloatPoint position, Optional<Gfx::IntRect> expanded_thumb_rect = {})
{
auto vertical = orientation == Gfx::Orientation::Vertical;
@@ -72,6 +84,7 @@ static Compositor::ScrollbarController::Drag begin_scrollbar_drag(Gfx::Orientati
Compositor::ScrollbarController controller;
controller.set_scrollbars(scrollbars);
+ show_scrollbars_by_scrolling_away_and_back(controller, scroll_node_index);
auto drag = controller.begin_drag(scroll_tree, visual_context_tree, scroll_state_snapshot, position);
VERIFY(drag.has_value());
return drag.release_value();
@@ -365,3 +378,37 @@ TEST_CASE(press_beside_thumb_pages_toward_pointer_until_thumb_reaches_it)
EXPECT_EQ(controller.paging_direction(0, 60, { 0, 30 }), 0);
EXPECT_EQ(controller.paging_direction(0, 60, { 0, 60 }), -1);
}
+
+TEST_CASE(scrollbar_that_has_faded_out_is_reported_hidden)
+{
+ Compositor::ScrollbarController controller;
+ controller.set_scrollbars({ scrollbar_painted_by_display_list() });
+ Compositing::ScrollStateSnapshot scroll_state_snapshot;
+ auto visual_context_tree = visual_context_tree_with_scroller();
+ auto start = MonotonicTime::now();
+
+ // A scrollbar starts out hidden, which the main thread hears once.
+ (void)controller.update_visibility(nullptr, scroll_state_snapshot, start);
+ auto changes = controller.take_visibility_changes();
+ EXPECT_EQ(changes.size(), 1u);
+ EXPECT(changes[0].vertical);
+ EXPECT(changes[0].hidden);
+ EXPECT(controller.take_visibility_changes().is_empty());
+
+ // A scroll shows it.
+ scroll_state_snapshot.set_device_offset_for_index(Compositing::SpatialNodeIndex { 1 }, { 0, 10 });
+ (void)controller.update_visibility(nullptr, scroll_state_snapshot, start);
+ changes = controller.take_visibility_changes();
+ EXPECT_EQ(changes.size(), 1u);
+ EXPECT(!changes[0].hidden);
+
+ // It is still shown while it fades out, and hidden once it has.
+ auto shown_until = start + Compositor::ScrollbarController::shown_duration_after_activity;
+ (void)controller.advance_fades(visual_context_tree, scroll_state_snapshot, shown_until);
+ (void)controller.advance_fades(visual_context_tree, scroll_state_snapshot, shown_until + half_fade_duration);
+ EXPECT(controller.take_visibility_changes().is_empty());
+ (void)controller.advance_fades(visual_context_tree, scroll_state_snapshot, shown_until + Compositing::OverlayFade::duration);
+ changes = controller.take_visibility_changes();
+ EXPECT_EQ(changes.size(), 1u);
+ EXPECT(changes[0].hidden);
+}