File tree 2 files changed +26
-9
lines changed
2 files changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -1328,12 +1328,22 @@ impl IOCompositor {
1328
1328
self . constellation_chan
1329
1329
. send ( EmbedderToConstellationMessage :: ForwardInputEvent (
1330
1330
webview_id,
1331
- event,
1331
+ event. clone ( ) ,
1332
1332
Some ( result) ,
1333
1333
) )
1334
1334
{
1335
1335
warn ! ( "Sending event to constellation failed ({error:?})." ) ;
1336
1336
}
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
+ }
1337
1347
}
1338
1348
1339
1349
/// Handle the input event in the window.
@@ -1370,6 +1380,15 @@ impl IOCompositor {
1370
1380
self . dispatch_input_event ( webview_id, event) ;
1371
1381
}
1372
1382
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
+
1373
1392
fn hit_test_at_point ( & self , point : DevicePoint ) -> Option < CompositorHitTestResult > {
1374
1393
self . hit_test_at_point_with_flags_and_pipeline ( point, HitTestFlags :: empty ( ) , None )
1375
1394
. first ( )
Original file line number Diff line number Diff line change @@ -519,16 +519,14 @@ impl Window {
519
519
}
520
520
} ;
521
521
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 ;
528
525
} ;
526
+
529
527
forward_input_event (
530
528
compositor,
531
- webview_id,
529
+ * webview_id,
532
530
sender,
533
531
InputEvent :: MouseButton ( event) ,
534
532
) ;
@@ -542,7 +540,7 @@ impl Window {
542
540
} ;
543
541
forward_input_event (
544
542
compositor,
545
- webview_id,
543
+ * webview_id,
546
544
sender,
547
545
InputEvent :: MouseButton ( event) ,
548
546
) ;
You can’t perform that action at this time.
0 commit comments