mirror of
https://github.com/lexmount/moli.git
synced 2026-11-24 16:02:53 +00:00
fix(inert): keep touch and CDP hits in the viewport document
This commit is contained in:
@@ -1398,6 +1398,122 @@ async fn get_node_for_location_can_hit_inert_overlay() {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn get_node_for_location_stays_in_the_inert_viewport_document() {
|
||||
for policy in [
|
||||
LayoutPolicy::Mock,
|
||||
LayoutPolicy::OnDemand,
|
||||
LayoutPolicy::Realtime,
|
||||
] {
|
||||
let mut ctx = TestContext::new_with_layout_policy(policy);
|
||||
load_bc(&mut ctx, "BID-A");
|
||||
navigate_to_data_html_async(
|
||||
&mut ctx,
|
||||
1,
|
||||
r#"<!doctype html><style>html,body{margin:0}</style>
|
||||
<iframe id="frame" style="position:absolute;left:65px;top:45px;width:80px;height:64px;border:8px solid"
|
||||
srcdoc="<!doctype html><style>html,body{margin:0}button{width:58px;height:24px}</style><button>child</button>"></iframe>"#,
|
||||
)
|
||||
.await;
|
||||
if policy.uses_real_layout() {
|
||||
ctx.capture_fixture_layout(None).await;
|
||||
}
|
||||
let child_frame = child_frame_id_for_single_iframe_async(&mut ctx, 2).await;
|
||||
let parent_root = renderer_backend_node_id_for_live_expression(
|
||||
&mut ctx,
|
||||
3,
|
||||
4,
|
||||
"document.documentElement",
|
||||
)
|
||||
.await;
|
||||
let child_root = renderer_backend_node_id_for_live_expression(
|
||||
&mut ctx,
|
||||
5,
|
||||
6,
|
||||
"frame.contentDocument.documentElement",
|
||||
)
|
||||
.await;
|
||||
let child_button = renderer_backend_node_id_for_live_expression(
|
||||
&mut ctx,
|
||||
7,
|
||||
8,
|
||||
"frame.contentDocument.querySelector('button')",
|
||||
)
|
||||
.await;
|
||||
let owner = renderer_backend_node_id_for_live_expression(&mut ctx, 9, 10, "frame").await;
|
||||
let geometry = ctx
|
||||
.evaluate_fixture_expression(
|
||||
r#"
|
||||
frame.contentDocument.documentElement.inert = true;
|
||||
const rect = frame.getBoundingClientRect();
|
||||
[Math.round(rect.left), Math.round(rect.top), innerWidth]
|
||||
"#,
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let left = geometry["value"][0].as_i64().unwrap();
|
||||
let top = geometry["value"][1].as_i64().unwrap();
|
||||
let viewport_width = geometry["value"][2].as_i64().unwrap();
|
||||
// Mock's 300px owner box extends beyond its child's 80px viewport.
|
||||
// With real layout, the corresponding owner hit is on the border.
|
||||
let (inset, outside_child) = if policy.uses_real_layout() {
|
||||
(8, 2)
|
||||
} else {
|
||||
(0, 85)
|
||||
};
|
||||
let x = left + inset + 10;
|
||||
let y = top + inset + 10;
|
||||
|
||||
for (id, x, ignore, expected_node, expected_frame) in [
|
||||
(11, x, false, child_root, child_frame.as_str()),
|
||||
(12, x, true, child_button, child_frame.as_str()),
|
||||
(13, left + outside_child, false, owner, "TID-1"),
|
||||
] {
|
||||
ctx.process_async(json!({
|
||||
"id": id,
|
||||
"method": "DOM.getNodeForLocation",
|
||||
"params": { "x": x, "y": y, "ignorePointerEventsNone": ignore }
|
||||
}))
|
||||
.await;
|
||||
let response = take_response_by_id(&mut ctx, id);
|
||||
assert_eq!(
|
||||
response["result"]["backendNodeId"],
|
||||
json!(expected_node),
|
||||
"{policy:?}: {response}"
|
||||
);
|
||||
assert_eq!(response["result"]["frameId"], json!(expected_frame));
|
||||
}
|
||||
|
||||
ctx.evaluate_fixture_expression("document.documentElement.inert = true", false)
|
||||
.await
|
||||
.unwrap();
|
||||
ctx.process_async(json!({
|
||||
"id": 14,
|
||||
"method": "DOM.getNodeForLocation",
|
||||
"params": { "x": x, "y": y }
|
||||
}))
|
||||
.await;
|
||||
let response = take_response_by_id(&mut ctx, 14);
|
||||
assert_eq!(
|
||||
response["result"]["backendNodeId"],
|
||||
json!(parent_root),
|
||||
"{policy:?}: {response}"
|
||||
);
|
||||
assert_eq!(response["result"]["frameId"], json!("TID-1"));
|
||||
|
||||
for (id, x) in [(15, -1), (16, viewport_width)] {
|
||||
ctx.process_async(json!({
|
||||
"id": id,
|
||||
"method": "DOM.getNodeForLocation",
|
||||
"params": { "x": x, "y": y }
|
||||
}))
|
||||
.await;
|
||||
ctx.expect_error(id, -32000, "No node found at given location");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn get_node_for_location_hits_atomic_input_in_front_of_wrapping_label() {
|
||||
let mut ctx = TestContext::new();
|
||||
|
||||
@@ -6,9 +6,8 @@ use moli_layout::{
|
||||
#[cfg(test)]
|
||||
use moli_layout::LayoutScrollbarHit;
|
||||
|
||||
use super::provider::{
|
||||
is_live_hit_source, live_interaction_target, observable_hit_test, observable_hit_test_all,
|
||||
};
|
||||
use super::mock::mock_input_hit_test;
|
||||
use super::provider::{is_live_hit_source, live_interaction_target};
|
||||
use crate::{document_runtime::DomHandle, native_bridge::PageScriptHost};
|
||||
|
||||
const CHILD_FRAME_DEPTH_LIMIT: usize = 16;
|
||||
@@ -85,10 +84,8 @@ pub(crate) fn input_surface_hit_test(
|
||||
mode: InputHitTestMode,
|
||||
) -> Result<InputSurfaceHit, LayoutError> {
|
||||
if !runtime.layout_policy().uses_real_layout() {
|
||||
let target =
|
||||
input_hit_test_via_documents(runtime, document, point, ignore_pointer_events_none, 0)?;
|
||||
return Ok(InputSurfaceHit {
|
||||
target,
|
||||
target: mock_input_hit_test(runtime, document, point, ignore_pointer_events_none),
|
||||
control: None,
|
||||
});
|
||||
}
|
||||
@@ -125,34 +122,6 @@ pub(crate) fn observable_deep_hit_test(
|
||||
.target)
|
||||
}
|
||||
|
||||
fn input_hit_test_via_documents(
|
||||
runtime: &PageScriptHost,
|
||||
document: DomHandle,
|
||||
point: LayoutPoint,
|
||||
ignore_pointer_events_none: bool,
|
||||
depth: usize,
|
||||
) -> Result<Option<DomHandle>, LayoutError> {
|
||||
let Some((layout_hit, target)) =
|
||||
live_hit_in_document(runtime, document, point, ignore_pointer_events_none)?
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
if depth < CHILD_FRAME_DEPTH_LIMIT
|
||||
&& let Some(child) = runtime.child_browsing_context_document_handle(target)
|
||||
&& let Some(transform) = layout_hit.embedded_viewport_hit_transform()
|
||||
{
|
||||
let child_target = input_hit_test_via_documents(
|
||||
runtime,
|
||||
child,
|
||||
transform.map_point(point),
|
||||
ignore_pointer_events_none,
|
||||
depth + 1,
|
||||
)?;
|
||||
return Ok(child_target.or(Some(target)));
|
||||
}
|
||||
Ok(Some(target))
|
||||
}
|
||||
|
||||
fn input_surface_hit_test_in_tree(
|
||||
runtime: &PageScriptHost,
|
||||
tree: &FrozenLayoutTree<DomHandle>,
|
||||
@@ -209,10 +178,9 @@ fn input_surface_hit_test_in_tree(
|
||||
live_hit_in_tree(runtime, tree, point, ignore_pointer_events_none)
|
||||
};
|
||||
let Some((layout_hit, target)) = live_dom_hit else {
|
||||
// A mouse hit inside a frame still belongs to its viewport when all
|
||||
// of its painted DOM candidates are inert.
|
||||
let use_viewport_target = mode == InputHitTestMode::Wheel
|
||||
|| (mode == InputHitTestMode::Mouse && tree.viewport.contains(point));
|
||||
// The viewport still belongs to this document when all its painted
|
||||
// candidates are inert.
|
||||
let use_viewport_target = mode == InputHitTestMode::Wheel || tree.viewport.contains(point);
|
||||
return Ok(InputSurfaceHit {
|
||||
target: use_viewport_target.then_some(tree.source_root()),
|
||||
control: None,
|
||||
@@ -277,27 +245,3 @@ fn live_hit_in_tree(
|
||||
.into_iter()
|
||||
.find_map(resolve_hit)
|
||||
}
|
||||
|
||||
fn live_hit_in_document(
|
||||
runtime: &PageScriptHost,
|
||||
document: DomHandle,
|
||||
point: LayoutPoint,
|
||||
ignore_pointer_events_none: bool,
|
||||
) -> Result<Option<(LayoutHit<DomHandle>, DomHandle)>, LayoutError> {
|
||||
let (_, first_hit) = observable_hit_test(runtime, document, point, ignore_pointer_events_none)?;
|
||||
let resolve_hit = |hit: LayoutHit<DomHandle>| {
|
||||
live_interaction_target(runtime, hit.source, ignore_pointer_events_none)
|
||||
.map(|target| (hit, target))
|
||||
};
|
||||
let live_first_hit = first_hit.and_then(resolve_hit);
|
||||
// A latest-layout snapshot may still contain a text fragment whose DOM
|
||||
// node was replaced after publication, and `inert` can change without
|
||||
// changing geometry. Walk the sampled paint stack only when the live DOM
|
||||
// rejects the foremost candidate. This check neither refreshes nor
|
||||
// invalidates layout; the common case retains the single-hit fast path.
|
||||
if live_first_hit.is_some() || first_hit.is_none() {
|
||||
return Ok(live_first_hit);
|
||||
}
|
||||
let (_, hits) = observable_hit_test_all(runtime, document, point, ignore_pointer_events_none)?;
|
||||
Ok(hits.into_iter().find_map(resolve_hit))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::document_runtime::DomHandle;
|
||||
use moli_browser_profile::DEFAULT_WINDOW_SURFACE_PROFILE;
|
||||
use moli_layout::LayoutPoint;
|
||||
use std::time::Instant;
|
||||
|
||||
use super::super::super::super::PageScriptHost;
|
||||
@@ -597,6 +598,25 @@ pub(crate) fn mock_hit_test_handle(
|
||||
x,
|
||||
y,
|
||||
ignore_pointer_events_none,
|
||||
false,
|
||||
0,
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "devtools"))]
|
||||
pub(in crate::native_bridge::element::geometry) fn mock_input_hit_test(
|
||||
runtime: &PageScriptHost,
|
||||
document_handle: DomHandle,
|
||||
point: LayoutPoint,
|
||||
ignore_pointer_events_none: bool,
|
||||
) -> Option<DomHandle> {
|
||||
mock_hit_test_handle_with_child_frames(
|
||||
runtime,
|
||||
document_handle,
|
||||
f64::from(point.x),
|
||||
f64::from(point.y),
|
||||
ignore_pointer_events_none,
|
||||
true,
|
||||
0,
|
||||
)
|
||||
}
|
||||
@@ -659,11 +679,19 @@ fn mock_hit_test_handle_with_child_frames(
|
||||
x: f64,
|
||||
y: f64,
|
||||
ignore_pointer_events_none: bool,
|
||||
use_viewport_fallback: bool,
|
||||
depth: usize,
|
||||
) -> Option<DomHandle> {
|
||||
if !x.is_finite() || !y.is_finite() {
|
||||
return None;
|
||||
}
|
||||
if use_viewport_fallback
|
||||
&& !runtime
|
||||
.layout_viewport_for_document(document_handle)
|
||||
.contains(LayoutPoint::new(x as f32, y as f32))
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let elements = document_elements_in_hit_order(runtime, document_handle);
|
||||
for element in elements.into_iter().rev() {
|
||||
let rect = mock_client_rect(runtime, element);
|
||||
@@ -680,6 +708,7 @@ fn mock_hit_test_handle_with_child_frames(
|
||||
x - rect.left,
|
||||
y - rect.top,
|
||||
ignore_pointer_events_none,
|
||||
use_viewport_fallback,
|
||||
depth + 1,
|
||||
)
|
||||
{
|
||||
@@ -702,5 +731,12 @@ fn mock_hit_test_handle_with_child_frames(
|
||||
return Some(element);
|
||||
}
|
||||
}
|
||||
None
|
||||
if use_viewport_fallback {
|
||||
runtime
|
||||
.dom_host()
|
||||
.dom()
|
||||
.document_element_handle_for_document(document_handle)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
mod layout;
|
||||
mod queries;
|
||||
|
||||
#[cfg(any(test, feature = "devtools"))]
|
||||
pub(super) use layout::mock_input_hit_test;
|
||||
pub(crate) use layout::{
|
||||
compute_mock_client_rect, compute_mock_intersection_client_rect,
|
||||
compute_mock_intersection_scrollport_client_rect,
|
||||
|
||||
@@ -126,6 +126,55 @@ fn mouse_input_in_an_inert_child_viewport_targets_its_document_root() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn touch_input_in_an_inert_child_viewport_targets_its_document_root() {
|
||||
use moli_page_types::LayoutPolicy;
|
||||
|
||||
for policy in [LayoutPolicy::OnDemand, LayoutPolicy::Realtime] {
|
||||
let mut vm = new_storage_html_test_vm("https://inert-child-touch-input.test/");
|
||||
vm.set_layout_policy(policy);
|
||||
vm.eval(
|
||||
r#"
|
||||
const frame = document.createElement('iframe');
|
||||
frame.style.cssText = 'position:absolute;left:65px;top:45px;width:320px;height:240px;border:0';
|
||||
document.body.appendChild(frame);
|
||||
const inner = frame.contentDocument;
|
||||
inner.body.innerHTML = '<button>child</button>';
|
||||
window.inputEvents = [];
|
||||
for (const [doc, source] of [[document, 'parent'], [inner, 'child']]) {
|
||||
for (const type of ['pointerdown', 'touchstart', 'pointerup', 'touchend', 'click']) {
|
||||
doc.addEventListener(type, event => {
|
||||
const point = event.changedTouches?.[0] ?? event;
|
||||
inputEvents.push([source, type, event.target.nodeName, point.clientX, point.clientY]);
|
||||
});
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
publish_layout_for_test(&mut vm);
|
||||
vm.eval("inner.documentElement.inert = true").unwrap();
|
||||
|
||||
vm.dispatch_touch_event_at_point(110.0, 105.0, "touchstart", false)
|
||||
.unwrap();
|
||||
vm.dispatch_touch_event_at_points(&[], "touchend", false)
|
||||
.unwrap();
|
||||
let outside = vm
|
||||
.dispatch_touch_event_at_point(-1.0, 105.0, "touchstart", false)
|
||||
.unwrap();
|
||||
assert!(!outside.handled, "{policy:?}");
|
||||
assert_eq!(
|
||||
vm.eval("JSON.stringify(inputEvents)").unwrap(),
|
||||
concat!(
|
||||
r#"[["child","pointerdown","HTML",45,60],["child","touchstart","HTML",45,60],"#,
|
||||
r#"["child","pointerup","HTML",45,60],["child","touchend","HTML",45,60],"#,
|
||||
r#"["child","click","HTML",45,60]]"#,
|
||||
),
|
||||
"{policy:?}",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mouse_boundary_events_leave_and_reenter_after_an_inert_hit_miss() {
|
||||
let mut vm = new_rendered_test_vm(
|
||||
|
||||
Reference in New Issue
Block a user