webdriver: Raise WebView to top when focus (#38909)

- Add a helper function `focus_and_raise_to_top` to `WebView`.
- For webdriver, raise webview to top when focus, to make it consistent
with user interaction.

Testing: Should reduce some flaky TIMEOUT when combined with another PR
later.
Fixes: A small patch before the PR for #38906.

---------

Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This commit is contained in:
Euclid Ye 2025-08-26 15:48:38 +08:00 committed by GitHub
parent 01a9b317d4
commit 8683f97fcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 14 additions and 16 deletions

View file

@ -58,8 +58,7 @@ impl ::servo::WebViewDelegate for AppState {
.hidpi_scale_factor(Scale::new(self.window.scale_factor() as f32))
.delegate(parent_webview.delegate())
.build();
webview.focus();
webview.raise_to_top(true);
webview.focus_and_raise_to_top(true);
self.webviews.borrow_mut().push(webview.clone());
Some(webview)
@ -117,8 +116,7 @@ impl ApplicationHandler<WakerEvent> for App {
.delegate(app_state.clone())
.build();
webview.focus();
webview.raise_to_top(true);
webview.focus_and_raise_to_top(true);
app_state.webviews.borrow_mut().push(webview);
*self = Self::Running(app_state);

View file

@ -408,6 +408,12 @@ impl WebView {
.expect("BUG: invalid WebView instance");
}
pub fn focus_and_raise_to_top(&self, hide_others: bool) -> FocusId {
let focus_id = self.focus();
self.raise_to_top(hide_others);
focus_id
}
pub fn notify_theme_change(&self, theme: Theme) {
self.inner()
.constellation_proxy

View file

@ -2482,7 +2482,7 @@ impl Handler {
let (sender, receiver) = ipc::channel().unwrap();
self.send_message_to_embedder(WebDriverCommandMsg::FocusWebView(webview_id, sender))?;
if wait_for_ipc_response(receiver)? {
debug!("Focus new webview successfully");
debug!("Focus new webview {webview_id} successfully");
} else {
debug!("Focus new webview failed, it may not exist anymore");
}