feat(windows): Expose webview2 zoom hotkeys from wry (#9352)

* Expose webview2 zoom hotkeys from wry

* Add change file

* Apply suggestions from code review

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>

* Regenerate schema files

---------

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
This commit is contained in:
Tony 2024-04-04 02:14:17 +08:00 committed by GitHub
parent 36b4c12497
commit 9273d7b379
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 58 additions and 2 deletions

View File

@ -0,0 +1,8 @@
---
"@tauri-apps/api": minor:feat
"tauri": minor:feat
"tauri-runtime": minor:feat
"tauri-runtime-wry": minor:feat
---
Add `zoom_hotkeys_enabled` to enable browser native zoom controls on creating webviews.

View File

@ -450,6 +450,11 @@
"null"
],
"format": "uri"
},
"zoomHotkeysEnabled": {
"description": "Whether page zooming by hotkeys is enabled **Windows Only**",
"default": false,
"type": "boolean"
}
},
"additionalProperties": false

View File

@ -3735,7 +3735,8 @@ fn create_webview<T: UserEvent>(
.with_focused(window.is_focused())
.with_url(&url)
.with_transparent(webview_attributes.transparent)
.with_accept_first_mouse(webview_attributes.accept_first_mouse);
.with_accept_first_mouse(webview_attributes.accept_first_mouse)
.with_hotkeys_zoom(webview_attributes.zoom_hotkeys_enabled);
#[cfg(windows)]
if kind == WebviewKind::WindowContent {

View File

@ -207,6 +207,7 @@ pub struct WebviewAttributes {
pub bounds: Option<Rect>,
pub auto_resize: bool,
pub proxy_url: Option<Url>,
pub zoom_hotkeys_enabled: bool,
}
impl From<&WindowConfig> for WebviewAttributes {
@ -233,6 +234,7 @@ impl From<&WindowConfig> for WebviewAttributes {
if let Some(url) = &config.proxy_url {
builder = builder.proxy_url(url.to_owned());
}
builder = builder.zoom_hotkeys_enabled(config.zoom_hotkeys_enabled);
builder
}
}
@ -255,6 +257,7 @@ impl WebviewAttributes {
bounds: None,
auto_resize: false,
proxy_url: None,
zoom_hotkeys_enabled: false,
}
}
@ -345,6 +348,13 @@ impl WebviewAttributes {
self.proxy_url = Some(url);
self
}
/// Whether page zooming by hotkeys is enabled
#[must_use]
pub fn zoom_hotkeys_enabled(mut self, enabled: bool) -> Self {
self.zoom_hotkeys_enabled = enabled;
self
}
}
/// IPC handler.

View File

@ -1293,6 +1293,9 @@ pub struct WindowConfig {
///
/// - **macOS**: Requires the `macos-proxy` feature flag and only compiles for macOS 14+.
pub proxy_url: Option<Url>,
/// Whether page zooming by hotkeys is enabled **Windows Only**
#[serde(default)]
pub zoom_hotkeys_enabled: bool,
}
impl Default for WindowConfig {
@ -1338,6 +1341,7 @@ impl Default for WindowConfig {
incognito: false,
parent: None,
proxy_url: None,
zoom_hotkeys_enabled: false,
}
}
}
@ -2259,6 +2263,7 @@ mod build {
let window_effects = opt_lit(self.window_effects.as_ref());
let incognito = self.incognito;
let parent = opt_str_lit(self.parent.as_ref());
let zoom_hotkeys_enabled = self.zoom_hotkeys_enabled;
literal_struct!(
tokens,
@ -2302,7 +2307,8 @@ mod build {
shadow,
window_effects,
incognito,
parent
parent,
zoom_hotkeys_enabled
);
}
}

View File

@ -775,6 +775,13 @@ fn main() {
self.webview_attributes.auto_resize = true;
self
}
/// Whether page zooming by hotkeys is enabled **Windows Only**
#[must_use]
pub fn zoom_hotkeys_enabled(mut self, enabled: bool) -> Self {
self.webview_attributes.zoom_hotkeys_enabled = enabled;
self
}
}
/// Webview.

View File

@ -40,6 +40,8 @@ mod desktop_commands {
window_effects: Option<WindowEffectsConfig>,
#[serde(default)]
incognito: bool,
#[serde(default)]
zoom_hotkeys_enabled: bool,
}
#[command(root = "crate")]
@ -77,6 +79,7 @@ mod desktop_commands {
builder.webview_attributes.accept_first_mouse = options.accept_first_mouse;
builder.webview_attributes.window_effects = options.window_effects;
builder.webview_attributes.incognito = options.incognito;
builder.webview_attributes.zoom_hotkeys_enabled = options.zoom_hotkeys_enabled;
window.add_child(
builder,

View File

@ -838,6 +838,13 @@ fn main() {
self.webview_builder = self.webview_builder.proxy_url(url);
self
}
/// Whether page zooming by hotkeys is enabled **Windows only**
#[must_use]
pub fn zoom_hotkeys_enabled(mut self, enabled: bool) -> Self {
self.webview_builder = self.webview_builder.zoom_hotkeys_enabled(enabled);
self
}
}
/// A type that wraps a [`Window`] together with a [`Webview`].

View File

@ -648,6 +648,10 @@ interface WebviewOptions {
* - **macOS**: Requires the `macos-proxy` feature flag and only compiles for macOS 14+.
* */
proxyUrl?: string
/**
* Whether page zooming by hotkeys or gestures is enabled **Windows Only**
*/
zoomHotkeysEnabled?: boolean
}
export { Webview, getCurrent, getAll }

View File

@ -450,6 +450,11 @@
"null"
],
"format": "uri"
},
"zoomHotkeysEnabled": {
"description": "Whether page zooming by hotkeys is enabled **Windows Only**",
"default": false,
"type": "boolean"
}
},
"additionalProperties": false