Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit 3162fa5

Browse files
committed
PRJ-58 Fix Markdown client components couldn't be shrunk
1 parent d17a18e commit 3162fa5

File tree

1 file changed

+51
-41
lines changed

1 file changed

+51
-41
lines changed

projector-client-web/src/main/kotlin/org/jetbrains/projector/client/web/component/MarkdownPanelManager.kt

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import org.jetbrains.projector.util.logging.Logger
3232
import org.w3c.dom.HTMLElement
3333
import org.w3c.dom.HTMLIFrameElement
3434
import org.w3c.dom.Node
35+
import org.w3c.dom.events.EventListener
3536
import org.w3c.dom.get
3637
import org.w3c.dom.parsing.DOMParser
3738
import kotlin.collections.component1
@@ -42,65 +43,74 @@ class MarkdownPanelManager(private val zIndexByWindowIdGetter: (Int) -> Int?, pr
4243

4344
private class MarkdownPanel(openInExternalBrowser: (String) -> Unit) {
4445

46+
private val documentListeners = mutableMapOf<String, EventListener>()
47+
4548
val iFrame: HTMLIFrameElement = createIFrame(openInExternalBrowser)
4649

4750
var windowId: Int? = null
4851

4952
fun dispose() {
53+
documentListeners.forEach { document.removeEventListener(it.key, it.value) }
5054
iFrame.remove()
5155
}
5256

53-
companion object {
57+
private fun createIFrame(openInExternalBrowser: (String) -> Unit) = (document.createElement("iframe") as HTMLIFrameElement).apply {
58+
style.apply {
59+
position = "fixed"
60+
backgroundColor = "#FFF"
61+
overflowX = "scroll"
62+
overflowY = "scroll"
63+
display = "none"
64+
}
5465

55-
private fun createIFrame(openInExternalBrowser: (String) -> Unit) = (document.createElement("iframe") as HTMLIFrameElement).apply {
56-
style.apply {
57-
position = "fixed"
58-
backgroundColor = "#FFF"
59-
overflowX = "scroll"
60-
overflowY = "scroll"
61-
display = "none"
62-
}
66+
frameBorder = "0"
6367

64-
frameBorder = "0"
68+
document.body!!.appendChild(this)
6569

66-
document.body!!.appendChild(this)
70+
// cancel auto-started load of about:blank in Firefox
71+
// https://stackoverflow.com/questions/7828502/cannot-set-document-body-innerhtml-of-iframe-in-firefox
72+
contentDocument!!.apply {
73+
open()
74+
close()
75+
}
6776

68-
// cancel auto-started load of about:blank in Firefox
69-
// https://stackoverflow.com/questions/7828502/cannot-set-document-body-innerhtml-of-iframe-in-firefox
70-
contentDocument!!.apply {
71-
open()
72-
close()
73-
}
77+
contentDocument!!.oncontextmenu = { false }
7478

75-
contentDocument!!.oncontextmenu = { false }
79+
documentListeners["mousedown"] = EventListener {
80+
style.asDynamic().pointerEvents = "none"
81+
}
82+
documentListeners["mouseup"] = EventListener {
83+
style.asDynamic().pointerEvents = "auto"
84+
}
7685

77-
// adopted from processLinks.js
78-
contentDocument!!.onclick = { e ->
79-
var target = e.target.asDynamic()
80-
while (target != null && target.tagName != "A") {
81-
target = target.parentNode
82-
}
86+
documentListeners.forEach { document.addEventListener(it.key, it.value) }
8387

84-
if (target == null) {
85-
true
86-
}
87-
else if (target.tagName == "A" && target.hasAttribute("href").unsafeCast<Boolean>()) {
88-
e.stopPropagation()
89-
90-
val href = target.getAttribute("href").unsafeCast<String>()
91-
if (href[0] == '#') {
92-
val elementId = href.substring(1)
93-
contentDocument!!.getElementById(elementId)?.scrollIntoView()
94-
}
95-
else {
96-
openInExternalBrowser(href)
97-
}
98-
99-
false
88+
// adopted from processLinks.js
89+
contentDocument!!.onclick = { e ->
90+
var target = e.target.asDynamic()
91+
while (target != null && target.tagName != "A") {
92+
target = target.parentNode
93+
}
94+
95+
if (target == null) {
96+
true
97+
}
98+
else if (target.tagName == "A" && target.hasAttribute("href").unsafeCast<Boolean>()) {
99+
e.stopPropagation()
100+
101+
val href = target.getAttribute("href").unsafeCast<String>()
102+
if (href[0] == '#') {
103+
val elementId = href.substring(1)
104+
contentDocument!!.getElementById(elementId)?.scrollIntoView()
100105
}
101106
else {
102-
null
107+
openInExternalBrowser(href)
103108
}
109+
110+
false
111+
}
112+
else {
113+
null
104114
}
105115
}
106116
}

0 commit comments

Comments
 (0)