From b8a07561f00480a45799b8f47fd89dd9cb4f48d4 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Sun, 24 Jul 2016 22:38:51 +0800 Subject: [PATCH] Enable swipe gesture only in content fix #2684 --- js/components/frame.js | 6 ++++++ js/components/main.js | 13 +++++++++++-- js/constants/messages.js | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/js/components/frame.js b/js/components/frame.js index 9d3f3608bf0..4cb16568cf2 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -438,6 +438,12 @@ class Frame extends ImmutableComponent { } }) this.webview.addEventListener('focus', this.onFocus) + this.webview.addEventListener('mouseenter', (e) => { + remote.getCurrentWindow().webContents.send(messages.ENABLE_SWIPE_GESTURE) + }) + this.webview.addEventListener('mouseleave', (e) => { + remote.getCurrentWindow().webContents.send(messages.DISABLE_SWIPE_GESTURE) + }) // @see new-window event this.webview.addEventListener('new-window', (e) => { e.preventDefault() diff --git a/js/components/main.js b/js/components/main.js index f160a0e0825..fecb0ad45b1 100644 --- a/js/components/main.js +++ b/js/components/main.js @@ -111,6 +111,7 @@ class Main extends ImmutableComponent { registerSwipeListener () { // Navigates back/forward on macOS two-finger swipe var trackingFingers = false + var swipeGesture = false var canSwipeBack = false var canSwipeForward = false var deltaX = 0 @@ -146,9 +147,17 @@ class Main extends ImmutableComponent { ipc.on(messages.CAN_SWIPE_FORWARD, (e) => { canSwipeForward = true }) + ipc.on(messages.ENABLE_SWIPE_GESTURE, (e) => { + swipeGesture = true + }) + ipc.on(messages.DISABLE_SWIPE_GESTURE, (e) => { + swipeGesture = false + }) ipc.on('scroll-touch-begin', function () { - trackingFingers = true - startTime = (new Date()).getTime() + if (swipeGesture) { + trackingFingers = true + startTime = (new Date()).getTime() + } }) ipc.on('scroll-touch-end', function () { if (time > 50 && trackingFingers && Math.abs(deltaY) < 50) { diff --git a/js/constants/messages.js b/js/constants/messages.js index d401294cedb..63f9069c501 100644 --- a/js/constants/messages.js +++ b/js/constants/messages.js @@ -81,6 +81,8 @@ const messages = { CAN_SWIPE_FORWARD: _, CHECK_SWIPE_BACK: _, CHECK_SWIPE_FORWARD: _, + ENABLE_SWIPE_GESTURE: _, + DISABLE_SWIPE_GESTURE: _, // Password manager GET_PASSWORDS: _, /** @arg {string} formOrigin, @arg {string} action */ GOT_PASSWORD: _, /** @arg {string} username, @arg {string} password, @arg {string} origin, @arg {string} action, @arg {boolean} isUnique */