add drag and drop event handler.

This commit is contained in:
Miroslav Šedivý 2021-01-07 20:21:40 +01:00
parent 9455fda582
commit dea3378cb0
2 changed files with 32 additions and 5 deletions

View File

@ -12,6 +12,7 @@
:implicitControl="state.control.implicit_hosting && state.members[state.member_id].profile.can_host"
@implicit-control-request="websocket.send('control/request')"
@implicit-control-release="websocket.send('control/release')"
@drop-files="api.room.uploadDrop($event)"
/>
</div>
</div>

View File

@ -11,6 +11,10 @@
@mouseup.stop.prevent="onMouseUp"
@mouseenter.stop.prevent="onMouseEnter"
@mouseleave.stop.prevent="onMouseLeave"
@dragenter.stop.prevent="onDrag"
@dragleave.stop.prevent="onDrag"
@dragover.stop.prevent="onDrag"
@drop.stop.prevent="onDrop"
/>
</template>
@ -95,13 +99,17 @@
// Guacamole Keyboard does not provide destroy functions
}
setMousePos(e: MouseEvent) {
getMousePos(clientX: number, clientY: number) {
const rect = this._overlay.getBoundingClientRect()
this.webrtc.send('mousemove', {
x: Math.round((this.screenWidth / rect.width) * (e.clientX - rect.left)),
y: Math.round((this.screenHeight / rect.height) * (e.clientY - rect.top)),
})
return {
x: Math.round((this.screenWidth / rect.width) * (clientX - rect.left)),
y: Math.round((this.screenHeight / rect.height) * (clientY - rect.top)),
}
}
setMousePos(e: MouseEvent) {
this.webrtc.send('mousemove', this.getMousePos(e.clientX, e.clientY))
}
onWheel(e: WheelEvent) {
@ -186,6 +194,24 @@
}
}
onDrag(e: DragEvent) {
e.preventDefault()
e.stopPropagation()
}
onDrop(e: DragEvent) {
e.preventDefault()
e.stopPropagation()
let dt = e.dataTransfer
if (!dt) return
let files = [...dt.files]
if (!files) return
this.$emit('drop-files', { ...this.getMousePos(e.clientX, e.clientY), files })
}
isRequesting = false
@Watch('isControling')
onControlChange(isControling: boolean) {