Permalink
Browse files

Make touch emulator less prone to state bugs

By continously listening to events, rather then binding and unbinding all the time.
  • Loading branch information...
koenbok committed Feb 3, 2016
1 parent 74b8b3b commit a23f2cda1b3e5f93c74e00a791ac78ed77d4f5f4
Showing with 11 additions and 19 deletions.
  1. +11 −19 framer/Extras/TouchEmulator.coffee
@@ -52,8 +52,10 @@ class TouchEmulator extends BaseClass
@wrap = @context.domEventManager.wrap
@wrap(document).addEventListener("mousedown", @mousedown, true)
@wrap(document).addEventListener("mousemove", @mousemovePosition, true)
@wrap(document).addEventListener("mousemove", @mousemove, true)
@wrap(document).addEventListener("mouseup", @mouseup, true)
@wrap(document).addEventListener("keydown", @keydown, true)
@wrap(document).addEventListener("keyup", @keyup, true)
@wrap(document).addEventListener("mouseout", @mouseout, true)
@isMouseDown = false
@@ -83,8 +85,6 @@ class TouchEmulator extends BaseClass
@showTouchCursor()
@touchPointLayer.midX = @point.x
@touchPointLayer.midY = @point.y
@wrap(document).addEventListener("keyup", @keyup, true)
@wrap(document).addEventListener("mousemove", @mousemove, true)
if event.keyCode is @keyPanCode
@isPanKeyDown = true
@@ -96,8 +96,6 @@ class TouchEmulator extends BaseClass
cancelEvent(event)
@isPinchKeyDown = false
@hideTouchCursor()
@wrap(document).removeEventListener("mousemove", @mousemove, true)
if event.keyCode is @keyPanCode
cancelEvent(event)
@@ -107,15 +105,12 @@ class TouchEmulator extends BaseClass
mousedown: (event) =>
cancelEvent(event)
@isMouseDown = true
@target = event.target
@wrap(document).addEventListener("mousemove", @mousemove, true)
@wrap(document).addEventListener("mouseup", @mouseup, true)
if @isPinchKeyDown
dispatchTouchEvent("touchstart", @target, event, @touchPointDelta)
else
@@ -124,13 +119,13 @@ class TouchEmulator extends BaseClass
@touchPointLayer.image = @touchPointerImageActive
mousemove: (event) =>
cancelEvent(event)
@point =
x: event.pageX
y: event.pageY
cancelEvent(event)
@startPoint ?= @point
@centerPoint ?= @point
@@ -149,10 +144,11 @@ class TouchEmulator extends BaseClass
@touchPointLayer.midX = @touchPoint.x
@touchPointLayer.midY = @touchPoint.y
if (@isPinchKeyDown or @isPanKeyDown) and @touchPointDelta
dispatchTouchEvent("touchmove", @target, event, @touchPointDelta)
else
dispatchTouchEvent("touchmove", @target, event)
if @isMouseDown
if (@isPinchKeyDown or @isPanKeyDown) and @touchPointDelta
dispatchTouchEvent("touchmove", @target, event, @touchPointDelta)
else
dispatchTouchEvent("touchmove", @target, event)
mouseup: (event) =>
@@ -204,10 +200,6 @@ class TouchEmulator extends BaseClass
y: event.pageY
endMultiTouch: ->
@wrap(document).removeEventListener("mousemove", @mousemove, true)
@wrap(document).removeEventListener("mouseup", @mouseup, true)
@isMouseDown = false
@touchPointLayer.image = @touchPointerImage
@hideTouchCursor()

0 comments on commit a23f2cd

Please sign in to comment.