Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2696 from darkdh/2684
Browse files Browse the repository at this point in the history
 Enable swipe gesture only when cursor is in content
  • Loading branch information
bbondy authored Jul 25, 2016
2 parents a943ba1 + b8a0756 commit f1714f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://github.com/atom/electron/blob/master/docs/api/web-view-tag.md#event-new-window">new-window event</a>
this.webview.addEventListener('new-window', (e) => {
e.preventDefault()
Expand Down
13 changes: 11 additions & 2 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions js/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit f1714f6

Please sign in to comment.