Skip to content

Truly independent web browser

LibWeb+LibCompositing: Record where nested contexts are painted

Aliaksandr Kalenik733b3e6bef94
diff --git a/Libraries/LibCompositing/DisplayList/DisplayList.cpp b/Libraries/LibCompositing/DisplayList/DisplayList.cpp
index 97009bd7aa1..0bccb541c31 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayList.cpp
+++ b/Libraries/LibCompositing/DisplayList/DisplayList.cpp
@@ -197,6 +197,8 @@ ErrorOr<void> encode(Encoder& encoder, Compositing::DisplayList::AsyncScrollingM
TRY(encoder.encode(metadata.wheel_event_listener_state_generation));
TRY(encoder.encode(metadata.has_blocking_wheel_event_listeners));
TRY(encoder.encode(metadata.has_blocking_wheel_event_region_covering_viewport));
+ TRY(encoder.encode(metadata.viewport_keeps_horizontal_scrolls));
+ TRY(encoder.encode(metadata.viewport_keeps_vertical_scrolls));
TRY(encoder.encode(metadata.device_pixels_per_css_pixel));
TRY(encoder.encode(metadata.keyboard_scroll_state));
return {};
@@ -211,6 +213,8 @@ ErrorOr<Compositing::DisplayList::AsyncScrollingMetadata> decode(Decoder& decode
.wheel_event_listener_state_generation = TRY(decoder.decode<u64>()),
.has_blocking_wheel_event_listeners = TRY(decoder.decode<bool>()),
.has_blocking_wheel_event_region_covering_viewport = TRY(decoder.decode<bool>()),
+ .viewport_keeps_horizontal_scrolls = TRY(decoder.decode<bool>()),
+ .viewport_keeps_vertical_scrolls = TRY(decoder.decode<bool>()),
.device_pixels_per_css_pixel = TRY(decoder.decode<double>()),
.keyboard_scroll_state = TRY(decoder.decode<Compositing::KeyboardScrollState>()),
};
diff --git a/Libraries/LibCompositing/DisplayList/DisplayList.h b/Libraries/LibCompositing/DisplayList/DisplayList.h
index 2e2fa8dd042..8aef8b66a75 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayList.h
+++ b/Libraries/LibCompositing/DisplayList/DisplayList.h
@@ -43,6 +43,10 @@ public:
u64 wheel_event_listener_state_generation { 0 };
bool has_blocking_wheel_event_listeners { false };
bool has_blocking_wheel_event_region_covering_viewport { false };
+ // Whether the viewport keeps the scrolls along an axis from the document it is nested in. A viewport with
+ // nothing to scroll has no scroll node to carry its overscroll-behavior.
+ bool viewport_keeps_horizontal_scrolls { false };
+ bool viewport_keeps_vertical_scrolls { false };
// Converts the compositor's device pixel offsets to the CSS pixels the snap geometry is in.
double device_pixels_per_css_pixel { 1.0 };
Compositing::KeyboardScrollState keyboard_scroll_state {};
diff --git a/Libraries/LibCompositing/Rust/src/display_list/commands.rs b/Libraries/LibCompositing/Rust/src/display_list/commands.rs
index 94b9aa0b72f..ba6e17330ee 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/commands.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/commands.rs
@@ -53,10 +53,12 @@ pub enum DisplayListCommandType {
CompositorSnapContainer,
CompositorSnapArea,
CompositorScrollChainingBarrier,
+ CompositorNestedContextWheelRegion,
}
ffi_enum_bytes!(DisplayListCommandType as u8);
-pub const DISPLAY_LIST_COMMAND_TYPE_COUNT: usize = DisplayListCommandType::CompositorScrollChainingBarrier as usize + 1;
+pub const DISPLAY_LIST_COMMAND_TYPE_COUNT: usize =
+ DisplayListCommandType::CompositorNestedContextWheelRegion as usize + 1;
impl DisplayListCommandType {
pub fn from_u8(value: u8) -> Option<Self> {
@@ -80,6 +82,7 @@ impl DisplayListCommandType {
| Self::CompositorSnapContainer
| Self::CompositorSnapArea
| Self::CompositorScrollChainingBarrier
+ | Self::CompositorNestedContextWheelRegion
)
}
@@ -122,6 +125,7 @@ impl DisplayListCommandType {
Self::CompositorSnapContainer => "CompositorSnapContainer",
Self::CompositorSnapArea => "CompositorSnapArea",
Self::CompositorScrollChainingBarrier => "CompositorScrollChainingBarrier",
+ Self::CompositorNestedContextWheelRegion => "CompositorNestedContextWheelRegion",
}
}
}
@@ -1530,6 +1534,25 @@ impl DisplayListCommand for CompositorScrollChainingBarrier {
const COMMAND_TYPE: DisplayListCommandType = DisplayListCommandType::CompositorScrollChainingBarrier;
}
+/// Where a nested context is painted: its content box, clipped to the rounded padding edge. The compositor can hand a
+/// wheel inside `rect` that nothing painted later covers to the nested context's own scroll nodes.
+#[derive(Clone, Copy, Debug, PartialEq)]
+#[repr(C)]
+pub struct CompositorNestedContextWheelRegion {
+ pub rect: FloatRect,
+ pub corner_radii: CornerRadii,
+ pub child_context_id: CompositorContextId,
+}
+ffi_bytes_fields!(CompositorNestedContextWheelRegion {
+ rect,
+ corner_radii,
+ child_context_id
+});
+
+impl DisplayListCommand for CompositorNestedContextWheelRegion {
+ const COMMAND_TYPE: DisplayListCommandType = DisplayListCommandType::CompositorNestedContextWheelRegion;
+}
+
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(C)]
pub struct CompositorMainThreadWheelEventRegion {
diff --git a/Libraries/LibCompositing/Rust/src/display_list/summary.rs b/Libraries/LibCompositing/Rust/src/display_list/summary.rs
index 0966e6f8287..b1b7ad75f53 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/summary.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/summary.rs
@@ -107,7 +107,8 @@ fn note_referenced_ids(command_type: DisplayListCommandType, payload: &[u8], ids
| T::PaintScrollBar
| T::CompositorSnapContainer
| T::CompositorSnapArea
- | T::CompositorScrollChainingBarrier => {}
+ | T::CompositorScrollChainingBarrier
+ | T::CompositorNestedContextWheelRegion => {}
}
}
@@ -235,7 +236,8 @@ fn command_blend(
| T::PaintScrollBar
| T::CompositorSnapContainer
| T::CompositorSnapArea
- | T::CompositorScrollChainingBarrier => None,
+ | T::CompositorScrollChainingBarrier
+ | T::CompositorNestedContextWheelRegion => None,
}
}
diff --git a/Libraries/LibCompositing/Rust/src/display_list/validate.rs b/Libraries/LibCompositing/Rust/src/display_list/validate.rs
index fc610e21ba4..598238c0a65 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/validate.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/validate.rs
@@ -292,6 +292,7 @@ fn command_struct_size(command_type: DisplayListCommandType) -> usize {
T::CompositorSnapContainer => size_of::<CompositorSnapContainer>(),
T::CompositorSnapArea => size_of::<CompositorSnapArea>(),
T::CompositorScrollChainingBarrier => size_of::<CompositorScrollChainingBarrier>(),
+ T::CompositorNestedContextWheelRegion => size_of::<CompositorNestedContextWheelRegion>(),
}
}
@@ -485,7 +486,8 @@ fn validate_command_fields(
| T::CompositorWheelHitTestTarget
| T::CompositorWheelHitTestTargetWithCornerRadii
| T::CompositorMainThreadWheelEventRegion
- | T::CompositorBlockingWheelEventRegion => {}
+ | T::CompositorBlockingWheelEventRegion
+ | T::CompositorNestedContextWheelRegion => {}
}
Ok(())
}
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
index 678c0e5be44..fe5abdeb45e 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
@@ -19,11 +19,13 @@ void AsyncScrollTree::set_state(AsyncScrollingState&& state)
m_device_pixels_per_css_pixel = state.device_pixels_per_css_pixel;
m_wheel_hit_test_regions = move(state.wheel_hit_test_targets);
m_main_thread_wheel_event_regions = move(state.main_thread_wheel_event_regions);
+ m_nested_context_wheel_regions = move(state.nested_context_wheel_regions);
m_blocking_wheel_event_regions = move(state.blocking_wheel_event_regions);
m_scroll_chaining_barriers = move(state.scroll_chaining_barriers);
m_has_blocking_wheel_event_region_covering_viewport = state.has_blocking_wheel_event_region_covering_viewport;
m_cached_wheel_hit_test_targets.clear();
m_cached_main_thread_wheel_event_targets.clear();
+ m_cached_nested_context_wheel_regions.clear();
m_cached_blocking_wheel_event_targets.clear();
m_cached_scroll_chaining_barriers.clear();
m_visual_context_tree_structural_epoch.clear();
@@ -273,6 +275,7 @@ void AsyncScrollTree::rebuild_wheel_hit_test_targets(RefPtr<Compositing::Display
{
m_cached_wheel_hit_test_targets.clear();
m_cached_main_thread_wheel_event_targets.clear();
+ m_cached_nested_context_wheel_regions.clear();
m_cached_blocking_wheel_event_targets.clear();
m_cached_scroll_chaining_barriers.clear();
m_visual_context_tree_structural_epoch.clear();
@@ -319,6 +322,16 @@ void AsyncScrollTree::rebuild_wheel_hit_test_targets(RefPtr<Compositing::Display
});
}
+ m_cached_nested_context_wheel_regions.ensure_capacity(m_nested_context_wheel_regions.size());
+ for (auto const& region : m_nested_context_wheel_regions) {
+ if (!context_is_valid(region.context))
+ continue;
+ m_cached_nested_context_wheel_regions.append({
+ .region = region,
+ .viewport_rect = viewport_rect_for_context(region.context, region.rect),
+ });
+ }
+
for (auto const& region : m_blocking_wheel_event_regions) {
// Keep invalid blockers so hit testing fails closed when their extent cannot be determined.
m_cached_blocking_wheel_event_targets.append({
@@ -341,18 +354,24 @@ void AsyncScrollTree::clear_wheel_hit_test_targets()
{
m_cached_wheel_hit_test_targets.clear();
m_cached_main_thread_wheel_event_targets.clear();
+ m_cached_nested_context_wheel_regions.clear();
m_cached_blocking_wheel_event_targets.clear();
m_cached_scroll_chaining_barriers.clear();
m_visual_context_tree_structural_epoch.clear();
}
-static bool wheel_hit_test_target_contains_point(CachedWheelHitTestTarget const& target, Gfx::FloatPoint position_in_context)
+static bool rounded_rect_contains_point(Gfx::FloatRect const& rect, Gfx::CornerRadii const& corner_radii, Gfx::FloatPoint position_in_context)
{
- if (!target.rect.contains(position_in_context))
+ if (!rect.contains(position_in_context))
return false;
- if (!target.corner_radii.has_any_radius())
+ if (!corner_radii.has_any_radius())
return true;
- return target.corner_radii.contains(position_in_context.to_type<int>(), target.rect.to_type<int>());
+ return corner_radii.contains(position_in_context.to_type<int>(), rect.to_type<int>());
+}
+
+static bool wheel_hit_test_target_contains_point(CachedWheelHitTestTarget const& target, Gfx::FloatPoint position_in_context)
+{
+ return rounded_rect_contains_point(target.rect, target.corner_radii, position_in_context);
}
Optional<Gfx::FloatPoint> AsyncScrollTree::scroll_offset_for_node(AsyncScrollNodeID node_id, Compositing::ScrollStateSnapshot const& scroll_state_snapshot) const
@@ -447,6 +466,18 @@ WheelHitTestResult AsyncScrollTree::hit_test_scroll_node_for_wheel(Compositing::
return { .outcome = WheelHitTestOutcome::BlockedByMainThreadRegion };
}
+ // The main thread hands a wheel over a nested context's content to the nested navigable.
+ for (auto const& cached_region : m_cached_nested_context_wheel_regions) {
+ auto const& region = cached_region.region;
+ if (cached_region.viewport_rect.has_value() && !cached_region.viewport_rect->contains(position))
+ continue;
+ if (!context_is_valid(region.context))
+ continue;
+ auto position_in_context = visual_context_tree.transform_point_for_hit_test(region.context, position, m_scroll_state_snapshot);
+ if (position_in_context.has_value() && rounded_rect_contains_point(region.rect, region.corner_radii, *position_in_context))
+ return { .outcome = WheelHitTestOutcome::BlockedByMainThreadRegion };
+ }
+
if (blocking_wheel_event_listeners_hold_the_step_back && blocks_wheel_event_at_position(visual_context_tree, position))
return { .outcome = WheelHitTestOutcome::BlockedByWheelEventRegion };
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h
index 1dca1196f18..2526c547d40 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h
@@ -82,6 +82,11 @@ struct CachedMainThreadWheelEventTarget {
Optional<Gfx::FloatRect> viewport_rect;
};
+struct CachedNestedContextWheelRegion {
+ NestedContextWheelRegion region;
+ Optional<Gfx::FloatRect> viewport_rect;
+};
+
struct CachedBlockingWheelEventTarget {
Compositing::ContextRef context;
Gfx::FloatRect rect;
@@ -157,9 +162,11 @@ private:
double m_device_pixels_per_css_pixel { 1.0 };
Vector<WheelHitTestTarget> m_wheel_hit_test_regions;
Vector<MainThreadWheelEventRegion> m_main_thread_wheel_event_regions;
+ Vector<NestedContextWheelRegion> m_nested_context_wheel_regions;
Vector<CachedWheelHitTestTarget> m_cached_wheel_hit_test_targets;
Vector<BlockingWheelEventRegion> m_blocking_wheel_event_regions;
Vector<CachedMainThreadWheelEventTarget> m_cached_main_thread_wheel_event_targets;
+ Vector<CachedNestedContextWheelRegion> m_cached_nested_context_wheel_regions;
Vector<CachedBlockingWheelEventTarget> m_cached_blocking_wheel_event_targets;
Vector<ScrollChainingBarrier> m_scroll_chaining_barriers;
Vector<CachedScrollChainingBarrier> m_cached_scroll_chaining_barriers;
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp
index 2836a468f92..faa90630ee7 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp
@@ -50,6 +50,8 @@ AsyncScrollingState async_scrolling_state_from_display_list(Compositing::Display
async_scrolling_state.wheel_event_listener_state_generation = metadata->wheel_event_listener_state_generation;
async_scrolling_state.has_blocking_wheel_event_listeners = metadata->has_blocking_wheel_event_listeners;
async_scrolling_state.has_blocking_wheel_event_region_covering_viewport = metadata->has_blocking_wheel_event_region_covering_viewport;
+ async_scrolling_state.viewport_keeps_horizontal_scrolls = metadata->viewport_keeps_horizontal_scrolls;
+ async_scrolling_state.viewport_keeps_vertical_scrolls = metadata->viewport_keeps_vertical_scrolls;
async_scrolling_state.device_pixels_per_css_pixel = metadata->device_pixels_per_css_pixel;
}
@@ -117,6 +119,17 @@ AsyncScrollingState async_scrolling_state_from_display_list(Compositing::Display
});
break;
}
+ case Compositing::DisplayListCommandType::CompositorNestedContextWheelRegion: {
+ auto command = Compositing::read_display_list_object<Compositing::CompositorNestedContextWheelRegion>(payload);
+ async_scrolling_state.nested_context_wheel_regions.append({
+ .context = context,
+ .rect = command.rect,
+ .corner_radii = command.corner_radii,
+ .child_context_id = command.child_context_id,
+ .paint_order_index = next_paint_order_index++,
+ });
+ break;
+ }
case Compositing::DisplayListCommandType::CompositorScrollChainingBarrier: {
auto command = Compositing::read_display_list_object<Compositing::CompositorScrollChainingBarrier>(payload);
async_scrolling_state.scroll_chaining_barriers.append({
@@ -298,6 +311,7 @@ JsonObject async_scrolling_state_to_json(AsyncScrollingState const& state)
object.set("hasBlockingWheelEventListeners"sv, state.has_blocking_wheel_event_listeners);
object.set("blockingWheelEventRegionCount"sv, state.blocking_wheel_event_regions.size());
object.set("mainThreadWheelEventRegionCount"sv, state.main_thread_wheel_event_regions.size());
+ object.set("nestedContextWheelRegionCount"sv, state.nested_context_wheel_regions.size());
object.set("wheelEventListenerStateGeneration"sv, state.wheel_event_listener_state_generation);
object.set("hasBlockingWheelEventRegionCoveringViewport"sv, state.has_blocking_wheel_event_region_covering_viewport);
return object;
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
index 9c93d2d6915..cd3e6f60c9f 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
@@ -23,6 +23,7 @@
#include <LibGfx/Point.h>
#include <LibGfx/Rect.h>
#include <LibWebCommon/Page/AsyncScrollNodeStableID.h>
+#include <LibWebCommon/Page/CompositorContextId.h>
#include <LibWebCommon/Page/InputRoutingDecision.h>
namespace Compositing {
@@ -98,6 +99,16 @@ struct MainThreadWheelEventRegion {
Gfx::FloatRect rect;
};
+// Where a nested context's content is painted. A wheel inside it that no wheel hit test target painted later covers
+// can be handed to the nested context.
+struct NestedContextWheelRegion {
+ Compositing::ContextRef context;
+ Gfx::FloatRect rect;
+ Gfx::CornerRadii corner_radii;
+ Web::CompositorContextId child_context_id;
+ u32 paint_order_index { 0 };
+};
+
// A scroll container without a scroll node of its own that keeps the scrolls along an axis to itself. A wheel inside
// its rect is not passed on along that axis to the scroll node above it.
struct ScrollChainingBarrier {
@@ -146,6 +157,7 @@ struct AsyncScrollingState {
Vector<AsyncSnapContainer> snap_containers;
Vector<WheelHitTestTarget> wheel_hit_test_targets;
Vector<MainThreadWheelEventRegion> main_thread_wheel_event_regions;
+ Vector<NestedContextWheelRegion> nested_context_wheel_regions;
Vector<ScrollChainingBarrier> scroll_chaining_barriers;
Vector<AsyncScrollbar> scrollbars;
@@ -161,6 +173,8 @@ struct AsyncScrollingState {
u64 wheel_event_listener_state_generation { 0 };
bool has_blocking_wheel_event_listeners { false };
bool has_blocking_wheel_event_region_covering_viewport { false };
+ bool viewport_keeps_horizontal_scrolls { false };
+ bool viewport_keeps_vertical_scrolls { false };
double device_pixels_per_css_pixel { 1.0 };
};
diff --git a/Libraries/LibWeb/Painting/PaintFacts.cpp b/Libraries/LibWeb/Painting/PaintFacts.cpp
index df5e872434b..9539174a60d 100644
--- a/Libraries/LibWeb/Painting/PaintFacts.cpp
+++ b/Libraries/LibWeb/Painting/PaintFacts.cpp
@@ -104,8 +104,9 @@ static Optional<u64> composited_context_id_for_navigable_container(HTML::Navigab
return context_id->value();
}
-void reconcile_navigable_container_paint_facts(Layout::BegunRead const& read, DOM::Document const& document)
+bool reconcile_navigable_container_paint_facts(Layout::BegunRead const& read, DOM::Document const& document)
{
+ bool has_composited_context = false;
for (auto const* navigable_container : HTML::NavigableContainer::all_instances()) {
if (&navigable_container->document() != &document)
continue;
@@ -116,10 +117,12 @@ void reconcile_navigable_container_paint_facts(Layout::BegunRead const& read, DO
if (auto context_id = composited_context_id_for_navigable_container(*navigable_container); context_id.has_value()) {
facts.has_composited_context = true;
facts.composited_context_id = *context_id;
+ has_composited_context = true;
}
// Where the facts changed, the container's paint cache goes with them.
Layout::RustFFI::render_state_set_navigable_container_paint_facts(layout_node->document_host(), Layout::Node::slot_id(layout_node), facts);
}
+ return has_composited_context;
}
static Layout::RustFFI::FfiNaturalSize natural_size_facts(Optional<CSSPixels> width, Optional<CSSPixels> height, Optional<CSSPixelFraction> aspect_ratio)
diff --git a/Libraries/LibWeb/Painting/PaintFacts.h b/Libraries/LibWeb/Painting/PaintFacts.h
index fdb1df74193..bc3a67c585e 100644
--- a/Libraries/LibWeb/Painting/PaintFacts.h
+++ b/Libraries/LibWeb/Painting/PaintFacts.h
@@ -27,7 +27,8 @@ WEB_API void push_layer_image_paint_facts(Layout::NodeWithStyle&);
WEB_API void push_replaced_image_paint_facts(Layout::Node&);
// The image the element provides changed.
WEB_API void push_replaced_image_paint_facts(DOM::Element const&, Layout::ImageProvider const&);
-WEB_API void reconcile_navigable_container_paint_facts(Layout::BegunRead const&, DOM::Document const&);
+// Returns whether the content of a navigable container of the document has a context the compositor draws.
+WEB_API bool reconcile_navigable_container_paint_facts(Layout::BegunRead const&, DOM::Document const&);
WEB_API void publish_image_map_area_facts_if_needed(Layout::BegunRead const&, DOM::Document&);
}
diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
index ec052e3f2bd..8849e9a9ba9 100644
--- a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
@@ -668,15 +668,23 @@ Optional<DisplayListRecording> start_rust_display_list_recording(Layout::BegunRe
inputs.bitmap_rect = bitmap_rect;
inputs.background_color = document.background_color(read);
}
- reconcile_navigable_container_paint_facts(read, document);
+ inputs.has_navigable_container_with_composited_context = reconcile_navigable_container_paint_facts(read, document);
Optional<Compositing::DisplayList::AsyncScrollingMetadata> async_scrolling_metadata;
if (auto navigable = document.navigable()) {
+ bool viewport_keeps_horizontal_scrolls = false;
+ bool viewport_keeps_vertical_scrolls = false;
+ if (auto* viewport_box = document.layout_node(read)) {
+ viewport_keeps_horizontal_scrolls = Painting::box_ending_scroll_chain(*viewport_box, 1, 0) == viewport_box;
+ viewport_keeps_vertical_scrolls = Painting::box_ending_scroll_chain(*viewport_box, 0, 1) == viewport_box;
+ }
async_scrolling_metadata = Compositing::DisplayList::AsyncScrollingMetadata {
.document_id = document.unique_id(),
.viewport_rect = device_viewport_rect.to_type<int>(),
.wheel_event_listener_state_generation = navigable->page().wheel_event_listener_state_generation(),
.has_blocking_wheel_event_listeners = wheel_event_region_state.has_blocking_wheel_event_listeners,
.has_blocking_wheel_event_region_covering_viewport = wheel_event_region_state.has_blocking_wheel_event_region_covering_viewport,
+ .viewport_keeps_horizontal_scrolls = viewport_keeps_horizontal_scrolls,
+ .viewport_keeps_vertical_scrolls = viewport_keeps_vertical_scrolls,
.device_pixels_per_css_pixel = device_pixels_per_css_pixel,
};
}
diff --git a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
index d4581d12304..fc294a85fa0 100644
--- a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
+++ b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
@@ -593,6 +593,11 @@ fn dump_command(output: &mut String, command_type: DisplayListCommandType, paylo
let command = read_command::<CompositorMainThreadWheelEventRegion>(payload);
write_field(output, "rect", command.rect);
}
+ DisplayListCommandType::CompositorNestedContextWheelRegion => {
+ let command = read_command::<CompositorNestedContextWheelRegion>(payload);
+ write_field(output, "rect", command.rect);
+ write_corner_radii(output, command.corner_radii);
+ }
DisplayListCommandType::CompositorScrollChainingBarrier => {
let command = read_command::<CompositorScrollChainingBarrier>(payload);
write_field(
diff --git a/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rs b/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rs
index 45e59ecdfea..bd0beb58c4a 100644
--- a/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rs
+++ b/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rs
@@ -1292,6 +1292,10 @@ impl DisplayListRecorder {
self.append_command(&barrier, &[]);
}
+ pub fn compositor_nested_context_wheel_region(&mut self, region: CompositorNestedContextWheelRegion) {
+ self.append_command(&region, &[]);
+ }
+
pub fn compositor_scrollbar(&mut self, scrollbar: CompositorScrollbar) {
self.append_command(&scrollbar, &[]);
}
diff --git a/Libraries/LibWeb/Rust/src/painting/host/paint.rs b/Libraries/LibWeb/Rust/src/painting/host/paint.rs
index 0f86833bf6f..42100650fdb 100644
--- a/Libraries/LibWeb/Rust/src/painting/host/paint.rs
+++ b/Libraries/LibWeb/Rust/src/painting/host/paint.rs
@@ -23,6 +23,7 @@ pub struct FfiRecordingInputs {
pub should_paint_overlay: bool,
pub document_id: i64,
pub has_blocking_wheel_event_region_covering_viewport: bool,
+ pub has_navigable_container_with_composited_context: bool,
pub wheel_event_listener_state_generation: u64,
pub chrome_metrics: crate::painting::ffi::FfiChromeMetrics,
pub paint_viewport_scrollbars: bool,
@@ -127,6 +128,7 @@ impl FfiRecordingInputs {
document_id: UniqueNodeId(self.document_id),
has_blocking_wheel_event_region_covering_viewport: self
.has_blocking_wheel_event_region_covering_viewport,
+ has_navigable_container_with_composited_context: self.has_navigable_container_with_composited_context,
chrome_metrics: self.chrome_metrics,
paint_viewport_scrollbars: self.paint_viewport_scrollbars,
middle_button_scroll_origin: self
diff --git a/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rs b/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rs
index 7ecc7d2dd01..8bf1c097a63 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rs
@@ -123,8 +123,8 @@ impl<O: Observer> PaintRecorder<'_, O> {
fn record_wheel_hit_test_target(&mut self, paintable: NodeSlotId) {
// OPTIMIZATION: The compositor falls back to the viewport when there are no explicit
// targets. Avoid generating redundant per-box targets when no non-viewport scroller
- // could need one.
- if !self.paint_state.has_non_viewport_wheel_scroll_target_candidate {
+ // or nested context could need one.
+ if !self.records_per_box_wheel_hit_test_targets {
return;
}
if !self.is_visible(paintable) || !self.visible_for_hit_testing(paintable) {
@@ -457,7 +457,15 @@ impl<O: Observer> PaintRecorder<'_, O> {
.source
.node_has_dom_paint_fact(paintable, DomPaintFact::NestedNavigableContainer)
{
- self.record_main_thread_wheel_event_region(paintable);
+ // A nested context the compositor can reach records a region of its own where its content is painted.
+ let has_composited_context = self
+ .source
+ .replaced_paint_facts(paintable)
+ .and_then(|facts| facts.navigable_container())
+ .is_some_and(|facts| facts.has_composited_context);
+ if !has_composited_context {
+ self.record_main_thread_wheel_event_region(paintable);
+ }
} else if let Some(scroll_node_kind) = self.kind_of_compositor_scroll_node_recorded_for(paintable) {
self.record_scroll_node(paintable, scroll_node_kind);
}
diff --git a/Libraries/LibWeb/Rust/src/painting/record/frame_inputs.rs b/Libraries/LibWeb/Rust/src/painting/record/frame_inputs.rs
index 86829a7a7ac..e5feb28f56d 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/frame_inputs.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/frame_inputs.rs
@@ -38,4 +38,9 @@ impl FrameInputs {
has_non_viewport_wheel_scroll_target_candidate: paint_state.has_non_viewport_wheel_scroll_target_candidate,
}
}
+
+ pub(crate) fn records_per_box_wheel_hit_test_targets(&self) -> bool {
+ self.has_non_viewport_wheel_scroll_target_candidate
+ || self.uncaptured.has_navigable_container_with_composited_context
+ }
}
diff --git a/Libraries/LibWeb/Rust/src/painting/record/inputs.rs b/Libraries/LibWeb/Rust/src/painting/record/inputs.rs
index 0c97c0bf8e0..9407cee0816 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/inputs.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/inputs.rs
@@ -24,6 +24,9 @@ pub(crate) struct UncapturedContentInputs {
pub device_viewport_size: IntSize,
pub document_id: UniqueNodeId,
pub has_blocking_wheel_event_region_covering_viewport: bool,
+ // The compositor hands a wheel over a nested context to it only where no box painted later covers it, which it can
+ // tell only from the wheel hit test targets of every box.
+ pub has_navigable_container_with_composited_context: bool,
pub chrome_metrics: FfiChromeMetrics,
pub paint_viewport_scrollbars: bool,
pub middle_button_scroll_origin: Option<CssPixelPoint>,
diff --git a/Libraries/LibWeb/Rust/src/painting/record/mod.rs b/Libraries/LibWeb/Rust/src/painting/record/mod.rs
index a3d91910308..2434c29b07e 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/mod.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/mod.rs
@@ -117,6 +117,7 @@ pub struct PaintRecorder<'a, O: Observer> {
// Rows of the layout subtrees whose root moved: every producer of theirs records again.
pub(crate) moved_expansion: FastSet<NodeSlotId>,
pub(crate) blocking_wheel_event_region_count: u32,
+ pub(crate) records_per_box_wheel_hit_test_targets: bool,
pub(crate) observer: O,
list: HitTestList,
pub(crate) scratch: &'a mut scratch::RecordingScratch,
diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/replaced.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/replaced.rs
index b4f4e12faf5..9fb5c65181d 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/paint/replaced.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/replaced.rs
@@ -12,7 +12,7 @@ use crate::css::css_pixels::CssPixels;
use crate::css::css_pixels::{CssPixelRect, CssPixelSize};
use crate::layout::node_data::NodeSlotId;
use crate::painting::display_list::builder::PendingInlineClip;
-use crate::painting::display_list::commands::{CanvasId, CompositorContextId};
+use crate::painting::display_list::commands::{CanvasId, CompositorContextId, CompositorNestedContextWheelRegion};
use crate::painting::force_dark::ForceDarkRole;
use crate::painting::paintable_geometry::absolute_rect;
use crate::painting::record::PaintRecorder;
@@ -441,20 +441,35 @@ pub(crate) fn paint_navigable_container_foreground<O: Observer>(
if let Some(corner_radii) = corner_radii {
inline_clips.push(PendingInlineClip::intersecting_rounded_rect(content_rect, corner_radii));
}
+ // Preserve fractional placement so the child raster uses the same pixel phase as content
+ // painted directly under the embedding transform.
+ let scale = recorder.converter.device_pixels_per_css_pixel();
+ let destination_rect = FloatRect::new(
+ (absolute_rect.x.to_double() * scale) as f32,
+ (absolute_rect.y.to_double() * scale) as f32,
+ (absolute_rect.width.to_double() * scale) as f32,
+ (absolute_rect.height.to_double() * scale) as f32,
+ );
+ let child_context_id = CompositorContextId(facts.composited_context_id);
recorder.record_with_inline_clips(&inline_clips, |recorder| {
- // Preserve fractional placement so the child raster uses the same pixel phase as content
- // painted directly under the embedding transform.
- let scale = recorder.converter.device_pixels_per_css_pixel();
- let destination_rect = FloatRect::new(
- (absolute_rect.x.to_double() * scale) as f32,
- (absolute_rect.y.to_double() * scale) as f32,
- (absolute_rect.width.to_double() * scale) as f32,
- (absolute_rect.height.to_double() * scale) as f32,
- );
- recorder.recorder.draw_composited_context(
- destination_rect,
- CompositorContextId(facts.composited_context_id),
- ScalingMode::NearestNeighbor,
- );
+ recorder
+ .recorder
+ .draw_composited_context(destination_rect, child_context_id, ScalingMode::NearestNeighbor);
});
+
+ // The compositor only reads the metadata outside groups, and a record under ambient clips would count as drawn.
+ if destination_rect.is_empty()
+ || !recorder.visible_for_hit_testing(paintable)
+ || recorder.recorder.is_recording_inside_group()
+ || recorder.is_recording_svg_resource_content()
+ {
+ return;
+ }
+ recorder
+ .recorder
+ .compositor_nested_context_wheel_region(CompositorNestedContextWheelRegion {
+ rect: destination_rect,
+ corner_radii: corner_radii.unwrap_or_default(),
+ child_context_id,
+ });
}
diff --git a/Libraries/LibWeb/Rust/src/painting/record/traversal.rs b/Libraries/LibWeb/Rust/src/painting/record/traversal.rs
index a4dacbcda39..f67feb319e6 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/traversal.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/traversal.rs
@@ -108,6 +108,7 @@ fn record_display_list_impl<O: Observer>(
live_producer: false,
moved_expansion: FastSet::default(),
blocking_wheel_event_region_count: 0,
+ records_per_box_wheel_hit_test_targets: frame_inputs.records_per_box_wheel_hit_test_targets(),
observer: O::default(),
list: HitTestList {
item_capacity_hint_from_previous_list: paint_state.hit_test_item_capacity_hint,
diff --git a/Libraries/LibWeb/Rust/src/painting/replaced_paint_facts.rs b/Libraries/LibWeb/Rust/src/painting/replaced_paint_facts.rs
index 5c7b969bf4e..b4694bab76a 100644
--- a/Libraries/LibWeb/Rust/src/painting/replaced_paint_facts.rs
+++ b/Libraries/LibWeb/Rust/src/painting/replaced_paint_facts.rs
@@ -88,11 +88,13 @@ pub(crate) enum ReplacedPaintFacts {
impl ReplacedPaintFacts {
/// The damage a row takes where its facts change to these. A canvas or a navigable container caches what it paints
- /// and is hit-tested with beside its row, which goes with the facts.
+ /// and is hit-tested with beside its row, which goes with the facts. Whether a navigable container's content is
+ /// composited also decides which wheel region its scroll metadata records.
pub(crate) fn damage_when_changed(&self) -> PaintDamage {
match self {
Self::FormControl(_) => PaintDamage::DRAW_FOREGROUND,
- Self::Canvas(_) | Self::NavigableContainer(_) => PaintDamage::ALL_DRAW | PaintDamage::ALL_HIT,
+ Self::Canvas(_) => PaintDamage::ALL_DRAW | PaintDamage::ALL_HIT,
+ Self::NavigableContainer(_) => PaintDamage::ALL_DRAW | PaintDamage::ALL_HIT | PaintDamage::SCROLL_METADATA,
Self::Image(_) | Self::Video(_) => PaintDamage::ALL_DRAW,
}
}
diff --git a/Services/Compositor/DisplayListPlayerSkia.cpp b/Services/Compositor/DisplayListPlayerSkia.cpp
index 1b07c178bb2..3edc9baecde 100644
--- a/Services/Compositor/DisplayListPlayerSkia.cpp
+++ b/Services/Compositor/DisplayListPlayerSkia.cpp
@@ -1440,6 +1440,10 @@ void DisplayListPlayerSkia::play_command(CompositorScrollChainingBarrier const&)
{
}
+void DisplayListPlayerSkia::play_command(CompositorNestedContextWheelRegion const&)
+{
+}
+
void DisplayListPlayerSkia::play_command(PaintScrollBar const& command)
{
paint_scrollbar_into_surface(surface(), command);
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/nested-navigable-wheel-admission.txt b/Tests/LibWeb/Text/expected/async-scrolling/nested-navigable-wheel-admission.txt
index 30cc302a2a5..585567b1938 100644
--- a/Tests/LibWeb/Text/expected/async-scrolling/nested-navigable-wheel-admission.txt
+++ b/Tests/LibWeb/Text/expected/async-scrolling/nested-navigable-wheel-admission.txt
@@ -1,4 +1,5 @@
-main thread regions: 1
+main thread regions: 0
+nested context regions: 1
over iframe: blocked-by-main-thread-region
outside iframe: latched scroller=viewport
display list:
@@ -10,7 +11,12 @@ AccumulatedVisualContext Tree:
[e0 in s0] effects=[]
DisplayList:
+CompositorWheelHitTestTarget@s0/e0 target_scroll_node_index=s1 rect=[0,0 800x600]
CompositorScrollNode@s0/e0 scroll_node_index=s1 parent_scroll_node_index=s0 scrollport_rect=[0,0 800x600] min_scroll_offset=[0,0] max_scroll_offset=[0,1413] is_viewport=true
-CompositorMainThreadWheelEventRegion@s1/e0 rect=[40,40 160x120]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s1 rect=[0,0 800x2013]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s1 rect=[0,0 800x2000]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s1 rect=[0,0 800x2000]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s1 rect=[40,40 160x120]
DrawCompositedContext@s1/e0 dst_rect=[40,40 160x120] inline_clips=[clip=[40,40 160x120]]
+CompositorNestedContextWheelRegion@s1/e0 rect=[40,40 160x120]
diff --git a/Tests/LibWeb/Text/expected/display_list/iframe-compositor-surface.txt b/Tests/LibWeb/Text/expected/display_list/iframe-compositor-surface.txt
index 507c144bd08..8ca70cf2cd1 100644
--- a/Tests/LibWeb/Text/expected/display_list/iframe-compositor-surface.txt
+++ b/Tests/LibWeb/Text/expected/display_list/iframe-compositor-surface.txt
@@ -6,6 +6,11 @@ AccumulatedVisualContext Tree:
[e0 in s0] effects=[]
DisplayList:
-CompositorMainThreadWheelEventRegion@s1/e0 rect=[0,0 120x80]
+CompositorWheelHitTestTarget@s0/e0 target_scroll_node_index=s0 rect=[0,0 800x600]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s0 rect=[0,0 800x93]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s0 rect=[0,0 800x80]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s0 rect=[0,0 800x80]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s0 rect=[0,0 120x80]
DrawCompositedContext@s1/e0 dst_rect=[0,0 120x80] inline_clips=[clip=[0,0 120x80]]
+CompositorNestedContextWheelRegion@s1/e0 rect=[0,0 120x80]
diff --git a/Tests/LibWeb/Text/input/async-scrolling/nested-navigable-wheel-admission.html b/Tests/LibWeb/Text/input/async-scrolling/nested-navigable-wheel-admission.html
index cc0a33f4ad0..4de2e787f52 100644
--- a/Tests/LibWeb/Text/input/async-scrolling/nested-navigable-wheel-admission.html
+++ b/Tests/LibWeb/Text/input/async-scrolling/nested-navigable-wheel-admission.html
@@ -38,12 +38,13 @@
// The compositor routes the wheel with the first frame that shows where the iframe is.
await waitForCondition(() => {
const state = internals.compositorScrollState();
- return state.document === document && state.mainThreadWheelEventRegionCount > 0;
+ return state.document === document && state.nestedContextWheelRegionCount > 0;
});
const state = internals.compositorScrollState();
const output = [
`main thread regions: ${state.mainThreadWheelEventRegionCount}`,
+ `nested context regions: ${state.nestedContextWheelRegionCount}`,
`over iframe: ${wheelTargetToString(internals.compositorWheelTargetAt(60, 60, 0, 100))}`,
`outside iframe: ${wheelTargetToString(internals.compositorWheelTargetAt(250, 60, 0, 100))}`,
];