Skip to content

Commit

Permalink
feat(win&linux): implement the option to control gesture navigation (#…
Browse files Browse the repository at this point in the history
…896)

* feat(Windows): add option to control swipe navigation, closes #895

* Update swipe-navigation.md

* implement `back_forward_navigation_gestures` on Linux and Windows

* Restore src/webview/wkwebview/mod.rs
  • Loading branch information
amrbashir authored Mar 7, 2023
1 parent 7b2f490 commit 15b4ddf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changes/win-linux-backwards-navigation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": "patch"
---

On Windows and Linux, implement `WebviewBuilder::with_back_forward_navigation_gestures` and `WebviewAttributes::back_forward_navigation_gestures` to control swipe navigation. Disabled by default.
10 changes: 4 additions & 6 deletions src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,9 @@ pub struct WebViewAttributes {

/// Indicates whether horizontal swipe gestures trigger backward and forward page navigation.
///
/// ## Platform-specific
/// ## Platform-specific:
///
/// This configuration only impacts macOS.
/// [Documentation](https://developer.apple.com/documentation/webkit/wkwebview/1414995-allowsbackforwardnavigationgestu).
/// - **Android / iOS:** Unsupported.
pub back_forward_navigation_gestures: bool,

/// Set a handler closure to process the change of the webview's document title.
Expand Down Expand Up @@ -339,10 +338,9 @@ impl<'a> WebViewBuilder<'a> {

/// Indicates whether horizontal swipe gestures trigger backward and forward page navigation.
///
/// ## Platform-specific
/// ## Platform-specific:
///
/// This configuration only impacts macOS.
/// [Documentation](https://developer.apple.com/documentation/webkit/wkwebview/1414995-allowsbackforwardnavigationgestu).
/// - **Android / iOS:** Unsupported.
pub fn with_back_forward_navigation_gestures(mut self, gesture: bool) -> Self {
self.webview.back_forward_navigation_gestures = gesture;
self
Expand Down
2 changes: 2 additions & 0 deletions src/webview/webkitgtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ impl InnerWebView {
if let Some(settings) = WebViewExt::settings(&*webview) {
settings.set_enable_webgl(true);
settings.set_enable_webaudio(true);
settings
.set_enable_back_forward_navigation_gestures(attributes.back_forward_navigation_gestures);

// Enable clipboard
if attributes.clipboard {
Expand Down
16 changes: 9 additions & 7 deletions src/webview/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,8 @@ impl InnerWebView {
.SetIsZoomControlEnabled(attributes.zoom_hotkeys_enabled)
.map_err(webview2_com::Error::WindowsError)?;
settings
.SetAreDevToolsEnabled(false)
.SetAreDevToolsEnabled(attributes.devtools)
.map_err(webview2_com::Error::WindowsError)?;
if attributes.devtools {
settings
.SetAreDevToolsEnabled(true)
.map_err(webview2_com::Error::WindowsError)?;
}
if !pl_attrs.browser_accelerator_keys {
if let Ok(settings3) = settings.cast::<ICoreWebView2Settings3>() {
settings3
Expand All @@ -265,7 +260,14 @@ impl InnerWebView {
}

let settings5 = settings.cast::<ICoreWebView2Settings5>()?;
let _ = settings5.SetIsPinchZoomEnabled(attributes.zoom_hotkeys_enabled);
settings5
.SetIsPinchZoomEnabled(attributes.zoom_hotkeys_enabled)
.map_err(webview2_com::Error::WindowsError)?;

let settings6 = settings.cast::<ICoreWebView2Settings6>()?;
settings6
.SetIsSwipeNavigationEnabled(attributes.back_forward_navigation_gestures)
.map_err(webview2_com::Error::WindowsError)?;

let mut rect = RECT::default();
win32wm::GetClientRect(hwnd, &mut rect);
Expand Down

0 comments on commit 15b4ddf

Please sign in to comment.