(target)
| 61 | const _captureObserver = new MutationObserver(_capturedElemChanged); |
| 62 | |
| 63 | export function setCapture(target) { |
| 64 | if (target.setCapture) { |
| 65 | |
| 66 | target.setCapture(); |
| 67 | document.captureElement = target; |
| 68 | } else { |
| 69 | // Release any existing capture in case this method is |
| 70 | // called multiple times without coordination |
| 71 | releaseCapture(); |
| 72 | |
| 73 | let proxyElem = document.getElementById("noVNC_mouse_capture_elem"); |
| 74 | |
| 75 | if (proxyElem === null) { |
| 76 | proxyElem = document.createElement("div"); |
| 77 | proxyElem.id = "noVNC_mouse_capture_elem"; |
| 78 | proxyElem.style.position = "fixed"; |
| 79 | proxyElem.style.top = "0px"; |
| 80 | proxyElem.style.left = "0px"; |
| 81 | proxyElem.style.width = "100%"; |
| 82 | proxyElem.style.height = "100%"; |
| 83 | proxyElem.style.zIndex = 10000; |
| 84 | proxyElem.style.display = "none"; |
| 85 | document.body.appendChild(proxyElem); |
| 86 | |
| 87 | // This is to make sure callers don't get confused by having |
| 88 | // our blocking element as the target |
| 89 | proxyElem.addEventListener('contextmenu', _captureProxy); |
| 90 | |
| 91 | proxyElem.addEventListener('mousemove', _captureProxy); |
| 92 | proxyElem.addEventListener('mouseup', _captureProxy); |
| 93 | } |
| 94 | |
| 95 | document.captureElement = target; |
| 96 | |
| 97 | // Track cursor and get initial cursor |
| 98 | _captureObserver.observe(target, {attributes: true}); |
| 99 | _capturedElemChanged(); |
| 100 | |
| 101 | proxyElem.style.display = ""; |
| 102 | |
| 103 | // We listen to events on window in order to keep tracking if it |
| 104 | // happens to leave the viewport |
| 105 | window.addEventListener('mousemove', _captureProxy); |
| 106 | window.addEventListener('mouseup', _captureProxy); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | export function releaseCapture() { |
| 111 | if (document.releaseCapture) { |
no test coverage detected