|
| 1 | +<html> |
| 2 | + <head> |
| 3 | + <style> |
| 4 | + body { |
| 5 | + background-color: rgba(67, 138, 138, 0.25); |
| 6 | + margin: 0px; |
| 7 | + } |
| 8 | + |
| 9 | + h1 { |
| 10 | + color: maroon; |
| 11 | + margin-left: 40px; |
| 12 | + } |
| 13 | + |
| 14 | + .caption { |
| 15 | + height: 40px; |
| 16 | + background-color: brown; |
| 17 | + } |
| 18 | + </style> |
| 19 | + <title>OsrWindow</title> |
| 20 | + </head> |
| 21 | + |
| 22 | + <body> |
| 23 | + <div> |
| 24 | + <div class="caption"></div> |
| 25 | + <button id="button">Button</button> |
| 26 | + <button id="doit">doit</button> |
| 27 | + <webview |
| 28 | + id="foo" |
| 29 | + src="https://www.google.com/" |
| 30 | + style="width: 640px; height: 480px" |
| 31 | + ></webview> |
| 32 | + <br /> |
| 33 | + Hello Electron! |
| 34 | + |
| 35 | + <label id="label">Label</label> |
| 36 | + <input type="text" /><input /> |
| 37 | + </div> |
| 38 | + <script> |
| 39 | + const label = document.getElementById("label"); |
| 40 | + setInterval(() => { |
| 41 | + label.innerText = new Date().toString(); |
| 42 | + // console.log(label.innerText) |
| 43 | + }, 1000); |
| 44 | + |
| 45 | + const { ipcRenderer, remote } = window.require("electron"); |
| 46 | + |
| 47 | + const button = document.getElementById("button"); |
| 48 | + button.addEventListener("click", () => { |
| 49 | + remote |
| 50 | + .getCurrentWindow() |
| 51 | + .setSize(window.innerWidth + 20, window.innerHeight + 20); |
| 52 | + console.log("button click ", new Date().toString()); |
| 53 | + ipcRenderer.send("osrClick"); |
| 54 | + }); |
| 55 | + |
| 56 | + const doit = document.getElementById("doit"); |
| 57 | + doit.addEventListener("click", () => { |
| 58 | + ipcRenderer.send("doit"); |
| 59 | + }); |
| 60 | + |
| 61 | + window.onfocus = function () { |
| 62 | + console.log("focus"); |
| 63 | + }; |
| 64 | + window.onblur = function () { |
| 65 | + console.log("blur"); |
| 66 | + }; |
| 67 | + |
| 68 | + ipcRenderer.on("proxyWebViewInput", (event, input) => { |
| 69 | + let views = document.getElementsByTagName("webview"); |
| 70 | + for (var i = 0; i < views.length; i++) { |
| 71 | + let view = views[i]; |
| 72 | + |
| 73 | + let newInput; |
| 74 | + if ( |
| 75 | + input.type === "mouseMove" || |
| 76 | + input.type === "mouseUp" || |
| 77 | + input.type === "mouseDown" |
| 78 | + ) { |
| 79 | + let bounds = view.getBoundingClientRect(); |
| 80 | + let newX = input.x - bounds.x; |
| 81 | + let newY = input.y - bounds.y; |
| 82 | + // make sure this is still inside the bounding box |
| 83 | + newInput = { ...input, x: newX, y: newY }; |
| 84 | + if ( |
| 85 | + newX >= 0 && |
| 86 | + newY >= 0 && |
| 87 | + newX <= bounds.width && |
| 88 | + newY <= bounds.height |
| 89 | + ) { |
| 90 | + view.sendInputEvent(newInput); |
| 91 | + } else { |
| 92 | + // we're outside of the web view |
| 93 | + if (input.type === "mouseDown") { |
| 94 | + view.executeJavaScript("document.activeElement.blur()"); |
| 95 | + } else { |
| 96 | + return; |
| 97 | + } |
| 98 | + } |
| 99 | + } else { |
| 100 | + // not the mouse, just send it over |
| 101 | + view.sendInputEvent(input); |
| 102 | + } |
| 103 | + } |
| 104 | + }); |
| 105 | + </script> |
| 106 | + </body> |
| 107 | +</html> |
0 commit comments