servo: Track async webview focus operations (#38243)

https://github.com/servo/servo/pull/38160 added a webdriver-specific API
to support waiting on focus operations to complete. These changes
replace that with a generalized pattern, where a unique ID is created
for each focus operation and the embedder can receive notifications
about each focus operation when it is complete, regardless of whether
the focus was actually changed.

Testing: Existing test coverage from
https://github.com/servo/servo/pull/38160/ is unchanged.

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-07-24 02:01:11 -04:00 committed by GitHub
parent 0b8986c8da
commit be38bd4636
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 99 additions and 77 deletions

View file

@ -327,8 +327,19 @@ pub struct ScreenMetrics {
pub available_size: DeviceIndependentIntSize,
}
/// An opaque identifier for a single webview focus operation.
#[derive(Clone, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct FocusId(String);
impl FocusId {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self(Uuid::new_v4().to_string())
}
}
/// An opaque identifier for a single history traversal operation.
#[derive(Clone, Deserialize, PartialEq, Serialize)]
#[derive(Clone, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct TraversalId(String);
impl TraversalId {
@ -372,10 +383,10 @@ pub enum EmbedderMsg {
AllowOpeningWebView(WebViewId, IpcSender<Option<(WebViewId, ViewportDetails)>>),
/// A webview was destroyed.
WebViewClosed(WebViewId),
/// A webview gained focus for keyboard events
/// If sender is provided, it will be used to send back a
/// bool indicating whether the focus was successfully set.
WebViewFocused(WebViewId, Option<IpcSender<bool>>),
/// A webview potentially gained focus for keyboard events, as initiated
/// by the provided focus id. If the boolean value is false, the webiew
/// could not be focused.
WebViewFocused(WebViewId, FocusId, bool),
/// All webviews lost focus for keyboard events.
WebViewBlurred,
/// Wether or not to unload a document