Skip to content

Commit

Permalink
feat: add feature to zoom webview contents, closes tauri-apps#388
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 committed Apr 30, 2022
1 parent b89398a commit 06efcda
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/impl-zoom-feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": minor
---

Add feature to zoom webview contents, closes #388.
2 changes: 2 additions & 0 deletions src/webview/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ impl InnerWebView {
}
}
}

pub fn zoom(&self, scale_factor: f64) {}
}

pub struct UnsafeIpc(*mut c_void);
Expand Down
4 changes: 4 additions & 0 deletions src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ impl WebView {
self.window.inner_size()
}

pub fn zoom(&self, scale_factor: f64) {
self.webview.zoom(scale_factor);
}

#[cfg(target_os = "android")]
pub fn run(self, env: JNIEnv, jclass: JClass, jobject: JObject) -> jobject {
self.webview.run(env, jclass, jobject).unwrap()
Expand Down
4 changes: 4 additions & 0 deletions src/webview/webkitgtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ impl InnerWebView {
pub fn is_devtools_open(&self) -> bool {
self.is_inspector_open.load(Ordering::Relaxed)
}

pub fn zoom(&self, scale_factor: f64) {
WebViewExt::set_zoom_level(&*self.webview, scale_factor);
}
}

pub fn platform_webview_version() -> Result<String> {
Expand Down
4 changes: 4 additions & 0 deletions src/webview/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,10 @@ window.addEventListener('mousemove', (e) => window.chrome.webview.postMessage('_
pub fn is_devtools_open(&self) -> bool {
false
}

pub fn zoom(&self, scale_factor: f64) {
let _ = unsafe { self.controller.SetZoomFactor(scale_factor) };
}
}

pub fn platform_webview_version() -> Result<String> {
Expand Down
7 changes: 7 additions & 0 deletions src/webview/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,13 @@ r#"Object.defineProperty(window, 'ipc', {
(view_frame.size.width as f64, view_frame.size.height as f64).into();
logical.to_physical(scale_factor)
}

#[cfg(target_os = "macos")]
pub fn zoom(&self, scale_factor: f64) {
unsafe {
let _: () = msg_send![self.webview, setPageZoom: scale_factor];
}
}
}

pub fn platform_webview_version() -> Result<String> {
Expand Down

0 comments on commit 06efcda

Please sign in to comment.