@@ -32,6 +32,7 @@ import org.jetbrains.projector.util.logging.Logger
32
32
import org.w3c.dom.HTMLElement
33
33
import org.w3c.dom.HTMLIFrameElement
34
34
import org.w3c.dom.Node
35
+ import org.w3c.dom.events.EventListener
35
36
import org.w3c.dom.get
36
37
import org.w3c.dom.parsing.DOMParser
37
38
import kotlin.collections.component1
@@ -42,65 +43,74 @@ class MarkdownPanelManager(private val zIndexByWindowIdGetter: (Int) -> Int?, pr
42
43
43
44
private class MarkdownPanel (openInExternalBrowser : (String ) -> Unit ) {
44
45
46
+ private val documentListeners = mutableMapOf<String , EventListener >()
47
+
45
48
val iFrame: HTMLIFrameElement = createIFrame(openInExternalBrowser)
46
49
47
50
var windowId: Int? = null
48
51
49
52
fun dispose () {
53
+ documentListeners.forEach { document.removeEventListener(it.key, it.value) }
50
54
iFrame.remove()
51
55
}
52
56
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
+ }
54
65
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"
63
67
64
- frameBorder = " 0 "
68
+ document.body !! .appendChild( this )
65
69
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
+ }
67
76
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 }
74
78
75
- contentDocument!! .oncontextmenu = { false }
79
+ documentListeners[" mousedown" ] = EventListener {
80
+ style.asDynamic().pointerEvents = " none"
81
+ }
82
+ documentListeners[" mouseup" ] = EventListener {
83
+ style.asDynamic().pointerEvents = " auto"
84
+ }
76
85
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) }
83
87
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()
100
105
}
101
106
else {
102
- null
107
+ openInExternalBrowser(href)
103
108
}
109
+
110
+ false
111
+ }
112
+ else {
113
+ null
104
114
}
105
115
}
106
116
}
0 commit comments