events: use pointer events to handle mouse events (resolves some conflict with touch events)
Using pointer events everywhere would be ideal but iOS<13 doesn't support them
This commit is contained in:
parent
86b3a1d3f3
commit
a3d252efb3
3 changed files with 25 additions and 22 deletions
|
|
@ -22,8 +22,7 @@ if (macOs) {
|
|||
|
||||
function mouseToFastClick(event) {
|
||||
|
||||
if (event.touchPunch) return
|
||||
if (event.sourceCapabilities && event.sourceCapabilities.firesTouchEvents) return
|
||||
if (event.pointerType === 'touch') return
|
||||
if (event.button == 2) event.preventDefault()
|
||||
|
||||
var e = event
|
||||
|
|
@ -38,6 +37,9 @@ function touchToFastClick(event) {
|
|||
|
||||
var e = event.changedTouches[0]
|
||||
|
||||
e.shiftKey = event.shiftKey
|
||||
e.ctrlKey = event.ctrlKey
|
||||
|
||||
DOM.dispatchEvent(e.target, 'fast-click', e)
|
||||
|
||||
if (e.preventOriginalEvent) event.preventDefault()
|
||||
|
|
@ -57,7 +59,7 @@ function touchToFastClick(event) {
|
|||
|
||||
}
|
||||
|
||||
if (!iOS) document.addEventListener('mousedown', mouseToFastClick, true)
|
||||
if (!iOS) document.addEventListener('pointerdown', mouseToFastClick, true)
|
||||
document.addEventListener('touchstart', touchToFastClick, {passive: false, capture: true})
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -136,21 +136,22 @@ function mouseMultiWrapper(event) {
|
|||
}
|
||||
|
||||
function mouseDownCapture(event, multitouch) {
|
||||
if ((event.sourceCapabilities && event.sourceCapabilities.firesTouchEvents) || event.button == 2) return
|
||||
event.pointerId = 'mouse'
|
||||
if (event.pointerType === 'touch') return
|
||||
// event.pointerId = 'mouse'
|
||||
event.multitouch = multitouch
|
||||
pointerDownHandler(event)
|
||||
}
|
||||
|
||||
function mouseMoveCapture(event) {
|
||||
event.pointerId = 'mouse'
|
||||
if (event.pointerType === 'touch') return
|
||||
// event.pointerId = 'mouse'
|
||||
event.inertia = event.ctrlKey ? 10 : 1
|
||||
pointerMoveFilter(event)
|
||||
}
|
||||
|
||||
function mouseUpCapture(event){
|
||||
if ((event.sourceCapabilities && event.sourceCapabilities.firesTouchEvents) || event.button == 2) return
|
||||
event.pointerId = 'mouse'
|
||||
if (event.pointerType === 'touch') return
|
||||
// event.pointerId = 'mouse'
|
||||
pointerUpFilter(event)
|
||||
}
|
||||
|
||||
|
|
@ -222,8 +223,8 @@ function triggerWidgetEvent(target, name, event) {
|
|||
// init
|
||||
|
||||
DOM.ready(()=>{
|
||||
if (!iOS) document.addEventListener('mousemove', mouseMoveCapture, true)
|
||||
if (!iOS) document.addEventListener('mouseup', mouseUpCapture, true)
|
||||
if (!iOS) document.addEventListener('pointermove', mouseMoveCapture, true)
|
||||
if (!iOS) document.addEventListener('pointerup', mouseUpCapture, true)
|
||||
document.addEventListener('touchmove', touchMoveCapture, true)
|
||||
DOM.addEventListener(document, 'touchend touchcancel', touchUpCapture, true)
|
||||
|
||||
|
|
@ -250,10 +251,10 @@ module.exports = {
|
|||
|
||||
if (multitouch) {
|
||||
element.addEventListener('touchstart', touchMultiWrapper, false)
|
||||
if (!iOS) element.addEventListener('mousedown', mouseMultiWrapper)
|
||||
if (!iOS) element.addEventListener('pointerdown', mouseMultiWrapper)
|
||||
} else {
|
||||
element.addEventListener('touchstart', touchDownCapture, false)
|
||||
if (!iOS) element.addEventListener('mousedown', mouseDownCapture)
|
||||
if (!iOS) element.addEventListener('pointerdown', mouseDownCapture)
|
||||
}
|
||||
|
||||
},
|
||||
|
|
@ -277,10 +278,10 @@ module.exports = {
|
|||
|
||||
if (multitouch) {
|
||||
element.removeEventListener('touchstart', touchMultiWrapper, false)
|
||||
if (!iOS) element.removeEventListener('mousedown', mouseMultiWrapper)
|
||||
if (!iOS) element.removeEventListener('pointerdown', mouseMultiWrapper)
|
||||
} else {
|
||||
element.removeEventListener('touchstart', touchDownCapture, false)
|
||||
if (!iOS) element.removeEventListener('mousedown', mouseDownCapture)
|
||||
if (!iOS) element.removeEventListener('pointerdown', mouseDownCapture)
|
||||
}
|
||||
|
||||
},
|
||||
|
|
@ -305,12 +306,12 @@ module.exports = {
|
|||
|
||||
}
|
||||
|
||||
if (!iOS) element.addEventListener('mousedown', makeEventTraversing, true)
|
||||
if (!iOS) element.addEventListener('pointerdown', makeEventTraversing, true)
|
||||
element.addEventListener('touchstart', makeEventTraversing, true)
|
||||
|
||||
element.addEventListener('disableTraversingGestures', (e)=>{
|
||||
e.stopPropagation()
|
||||
if (!iOS) element.removeEventListener('mousedown', makeEventTraversing, true)
|
||||
if (!iOS) element.removeEventListener('pointerdown', makeEventTraversing, true)
|
||||
element.removeEventListener('touchstart', makeEventTraversing, true)
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -109,17 +109,17 @@ class UiSelectArea {
|
|||
|
||||
enable() {
|
||||
|
||||
document.addEventListener('mousedown', this.bindedMousedown)
|
||||
document.addEventListener('mousemove', this.bindedMousemove, true)
|
||||
document.addEventListener('mouseup', this.bindedMouseup)
|
||||
document.addEventListener('pointerdown', this.bindedMousedown)
|
||||
document.addEventListener('pointermove', this.bindedMousemove, true)
|
||||
document.addEventListener('pointerup', this.bindedMouseup)
|
||||
|
||||
}
|
||||
|
||||
disable() {
|
||||
|
||||
document.removeEventListener('mousedown', this.bindedMousedown)
|
||||
document.removeEventListener('mousemove', this.bindedMousemove, true)
|
||||
document.removeEventListener('mouseup', this.bindedMouseup)
|
||||
document.removeEventListener('pointerdown', this.bindedMousedown)
|
||||
document.removeEventListener('pointermove', this.bindedMousemove, true)
|
||||
document.removeEventListener('pointerup', this.bindedMouseup)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue