Skip to content

Commit f634b22

Browse files
committed
Merge branch 'fix-focus-webview-when-click' into 'main'
fix: force update focused webview_id when mouse click on a webview See merge request verso-browser/verso!336
2 parents e7609fc + 8cc6399 commit f634b22

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/compositor.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,12 +1328,22 @@ impl IOCompositor {
13281328
self.constellation_chan
13291329
.send(EmbedderToConstellationMessage::ForwardInputEvent(
13301330
webview_id,
1331-
event,
1331+
event.clone(),
13321332
Some(result),
13331333
))
13341334
{
13351335
warn!("Sending event to constellation failed ({error:?}).");
13361336
}
1337+
1338+
// If the event is a mouse button, send FocusWebView event to the constellation.
1339+
// the webview will update current focused webview_id in the EmbedderMsg::WebViewFocused event.
1340+
if let InputEvent::MouseButton(event) = &event {
1341+
if event.action == MouseButtonAction::Click {
1342+
let _ = self
1343+
.constellation_chan
1344+
.send(EmbedderToConstellationMessage::FocusWebView(webview_id));
1345+
}
1346+
}
13371347
}
13381348

13391349
/// Handle the input event in the window.
@@ -1370,6 +1380,15 @@ impl IOCompositor {
13701380
self.dispatch_input_event(webview_id, event);
13711381
}
13721382

1383+
/// Get the webview id from a point.
1384+
pub(crate) fn webview_id_from_point(&self, point: DevicePoint) -> Option<WebViewId> {
1385+
self.hit_test_at_point(point)
1386+
.map(|result| result.pipeline_id)
1387+
.and_then(|pipeline_id| self.pipeline_details.get(&pipeline_id))
1388+
.and_then(|details| details.pipeline.clone())
1389+
.map(|pipeline| pipeline.webview_id)
1390+
}
1391+
13731392
fn hit_test_at_point(&self, point: DevicePoint) -> Option<CompositorHitTestResult> {
13741393
self.hit_test_at_point_with_flags_and_pipeline(point, HitTestFlags::empty(), None)
13751394
.first()

src/window.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,14 @@ impl Window {
519519
}
520520
};
521521

522-
let webview_id = match self.focused_webview_id {
523-
Some(webview_id) => webview_id,
524-
None => {
525-
log::trace!("No focused webview, skipping MouseInput event.");
526-
return;
527-
}
522+
let Some(webview_id) = &compositor.webview_id_from_point(point) else {
523+
log::trace!("No webview at point, skipping MouseInput event.");
524+
return;
528525
};
526+
529527
forward_input_event(
530528
compositor,
531-
webview_id,
529+
*webview_id,
532530
sender,
533531
InputEvent::MouseButton(event),
534532
);
@@ -542,7 +540,7 @@ impl Window {
542540
};
543541
forward_input_event(
544542
compositor,
545-
webview_id,
543+
*webview_id,
546544
sender,
547545
InputEvent::MouseButton(event),
548546
);

0 commit comments

Comments
 (0)