Skip to content

Commit

Permalink
Prevent two-finger swipe forard/back when scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Jul 18, 2016
1 parent 60c5314 commit ddff3ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/extensions/brave/content/scripts/inputHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,7 @@ document.addEventListener('keydown', (e /*: Event*/) => {
break
}
})

document.addEventListener('scroll', (e) => {
chrome.ipc.sendToHost('got-scroll')
})
3 changes: 3 additions & 0 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ class Frame extends ImmutableComponent {
case messages.GO_FORWARD:
method = () => this.webview.goForward()
break
case messages.GOT_SCROLL:
remote.getCurrentWindow().webContents.send(messages.GOT_SCROLL)
break
case messages.NEW_FRAME:
method = (frameOpts, openInForeground) => {
windowActions.newFrame(frameOpts, openInForeground)
Expand Down
7 changes: 6 additions & 1 deletion js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Main extends ImmutableComponent {
registerSwipeListener () {
// Navigates back/forward on macOS two-finger swipe
var trackingFingers = false
var isScroll = false
var deltaX = 0
var deltaY = 0
var startTime = 0
Expand All @@ -125,12 +126,15 @@ class Main extends ImmutableComponent {
yVelocity = deltaY / time
}
})
ipc.on(messages.GOT_SCROLL, (e) => {
isScroll = true
})
ipc.on('scroll-touch-begin', function () {
trackingFingers = true
startTime = (new Date()).getTime()
})
ipc.on('scroll-touch-end', function () {
if (trackingFingers && Math.abs(yVelocity) < 1) {
if (!isScroll && trackingFingers && Math.abs(yVelocity) < 1) {
if (xVelocity > 1.5) {
ipc.emit(messages.SHORTCUT_ACTIVE_FRAME_FORWARD)
} else if (xVelocity < -1.5) {
Expand All @@ -141,6 +145,7 @@ class Main extends ImmutableComponent {
deltaX = 0
deltaY = 0
startTime = 0
isScroll = false
})
ipc.on(messages.LEAVE_FULL_SCREEN, this.exitFullScreen.bind(this))
}
Expand Down
1 change: 1 addition & 0 deletions js/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const messages = {
SET_RESOURCE_ENABLED: _,
GO_BACK: _,
GO_FORWARD: _,
GOT_SCROLL: _,
GOT_PDFJS_URL: _, /** @arg {string} origin - of PDFJS extension */
// Password manager
GET_PASSWORDS: _, /** @arg {string} formOrigin, @arg {string} action */
Expand Down

0 comments on commit ddff3ff

Please sign in to comment.