Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactivity: wheel tool fix for firefox #1116

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Dispose event handlers on plot update instead of watching for the isC…
…onnected property
  • Loading branch information
IKupriyanov-HORIS committed Jun 17, 2024
commit 932896dd6f70597c7cb03925ee7a068958583a31
39 changes: 19 additions & 20 deletions js-package/src/jsMain/kotlin/FigureToHtml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal class FigureToHtml(
}

val svgRoot = buildInfo.createSvgRoot()
val toolEventDispatcher = if (svgRoot is CompositeFigureSvgRoot) {
val (toolEventDispatcher, eventsRegistration) = if (svgRoot is CompositeFigureSvgRoot) {
processCompositeFigure(
svgRoot,
origin = null, // The topmost SVG
Expand All @@ -82,7 +82,7 @@ internal class FigureToHtml(
)
}

val registration = object : Registration() {
val domCleanupRegistration = object : Registration() {
override fun doRemove() {
while (containerElement.firstChild != null) {
containerElement.removeChild(containerElement.firstChild!!)
Expand All @@ -92,11 +92,14 @@ internal class FigureToHtml(

return Result(
toolEventDispatcher,
registration
CompositeRegistration().add(
eventsRegistration,
domCleanupRegistration
)
)
}

class Result(
data class Result(
val toolEventDispatcher: ToolEventDispatcher,
val figureRegistration: Registration
)
Expand All @@ -107,10 +110,10 @@ internal class FigureToHtml(
parentElement: HTMLElement,
eventTarget: Element,
eventArea: DoubleRectangle
): ToolEventDispatcher {
): Pair<ToolEventDispatcher, Registration> {

val plotContainer = PlotContainer(svgRoot)
val rootSVG: SVGSVGElement = buildPlotFigureSVG(plotContainer, parentElement, eventTarget, eventArea)
val (rootSVG, cleanupRegistration) = buildPlotFigureSVG(plotContainer, parentElement, eventTarget, eventArea)
rootSVG.style.setCursor(CssCursor.CROSSHAIR)

// Livemap cursor pointer
Expand All @@ -121,15 +124,15 @@ internal class FigureToHtml(
}

parentElement.appendChild(rootSVG)
return plotContainer.toolEventDispatcher
return plotContainer.toolEventDispatcher to cleanupRegistration
}

private fun processCompositeFigure(
svgRoot: CompositeFigureSvgRoot,
origin: DoubleVector?,
parentElement: HTMLElement,
eventTarget: Element,
): ToolEventDispatcher {
): Pair<ToolEventDispatcher, Registration> {
svgRoot.ensureContentBuilt()

val rootSvgSvg: SvgSvgElement = svgRoot.svg
Expand Down Expand Up @@ -173,7 +176,7 @@ internal class FigureToHtml(
}
}

return UnsupportedToolEventDispatcher()
return UnsupportedToolEventDispatcher() to Registration.EMPTY
}

fun setupRootHTMLElement(element: HTMLElement, size: DoubleVector) {
Expand Down Expand Up @@ -203,9 +206,8 @@ internal class FigureToHtml(
plotContainer: PlotContainer,
parentElement: Element,
eventTarget: Element,
eventArea: DoubleRectangle
): SVGSVGElement {
val disposer = CompositeRegistration()
eventArea: DoubleRectangle,
): Pair<SVGSVGElement, Registration> {
val svg: SVGSVGElement = mapSvgToSVG(plotContainer.svg)

if (plotContainer.isLiveMap) {
Expand All @@ -215,7 +217,9 @@ internal class FigureToHtml(
}

val plotMouseEventMapper = DomMouseEventMapper(eventTarget, eventArea)
disposer.add(Registration.from(plotMouseEventMapper))

val eventsRegistration = CompositeRegistration()
eventsRegistration.add(Registration.from(plotMouseEventMapper))

plotContainer.mouseEventPeer.addEventSource(plotMouseEventMapper)

Expand All @@ -237,7 +241,7 @@ internal class FigureToHtml(
bounds.dimension.toDoubleVector()
)
)
disposer.add(Registration.from(canvasMouseEventMapper))
eventsRegistration.add(Registration.from(canvasMouseEventMapper))

val canvasControl = DomCanvasControl(
myRootElement = liveMapDiv,
Expand All @@ -251,12 +255,7 @@ internal class FigureToHtml(
liveMapDiv.onDisconnect(liveMapReg::dispose)
}

// TODO: temporary solution. Dispose in FigureToHtml.Result.figureRegistration instead.
svg.onDisconnect {
println("Plot disconnected")
disposer.dispose()
}
return svg
return svg to eventsRegistration
}

private fun Node.onDisconnect(onDisconnected: () -> Unit): Int {
Expand Down