Commit 6227658d authored by Bas Lijnse's avatar Bas Lijnse

Merge branch '351-fix-onNclick' into 'master'

Fix array out-of-bounds in onNclick handler of SVG editor

Closes #351

See merge request !340
parents 3fdb2769 c630a973
Pipeline #31266 passed with stage
in 6 minutes and 29 seconds
......@@ -737,26 +737,37 @@ where
// Translate the raw DOM coordinates to SVG coordinates relative to the image of the handler
// https://www.sitepoint.com/how-to-translate-from-dom-to-svg-coordinates-and-back-again
// Get the absolute coordinates for the viewport
#! (point, world) = (svg `createSVGPoint` ()) world
#! world = (point .# "x" .= args.[0] .# "clientX") world
#! world = (point .# "y" .= args.[0] .# "clientY") world
#! (m, world) = (svg `getScreenCTM` ()) world
#! (inv, world) = (m `inverse` ()) world
#! (point, world) = (point `matrixTransform` inv) world
#! (ax, world) = point .# "x" .? world
#! (ay, world) = point .# "y" .? world
#! (ax, ay) = (jsValToReal` 0.0 ax, jsValToReal` 0.0 ay)
// Get the coordinates for the image that was clicked in
#! (bRect, world) = (args.[0] .# "target" .# "getBoundingClientRect" .$ ()) world
#! (ix, world) = bRect .# "left" .? world
#! (iy, world) = bRect .# "top" .? world
#! (ix, iy) = (jsValToReal` 0.0 ix, jsValToReal` 0.0 iy)
// Compensate for the scrolling
#! (sx, world) = jsWindow .# "scrollX" .? world
#! (sy, world) = jsWindow .# "scrollY" .? world
#! (sx, sy) = (jsValToReal` 0.0 sx, jsValToReal` 0.0 sy)
# (span, world) = case size args of
0
// The onNclick handler does not give any arguments, so we
// do not have an event from which we can get the clientX
// and clientY. The span is not used in
// applyImgEventhandler, so we can use undef here.
-> (undef, world)
_
// All other handlers get a span from the JavaScript event,
// which is the first argument.
#! (point, world) = (svg `createSVGPoint` ()) world
#! world = (point .# "x" .= args.[0] .# "clientX") world
#! world = (point .# "y" .= args.[0] .# "clientY") world
#! (m, world) = (svg `getScreenCTM` ()) world
#! (inv, world) = (m `inverse` ()) world
#! (point, world) = (point `matrixTransform` inv) world
#! (ax, world) = point .# "x" .? world
#! (ay, world) = point .# "y" .? world
#! (ax, ay) = (jsValToReal` 0.0 ax, jsValToReal` 0.0 ay)
// Get the coordinates for the image that was clicked in
#! (bRect, world) = (args.[0] .# "target" .# "getBoundingClientRect" .$ ()) world
#! (ix, world) = bRect .# "left" .? world
#! (iy, world) = bRect .# "top" .? world
#! (ix, iy) = (jsValToReal` 0.0 ix, jsValToReal` 0.0 iy)
// Compensate for the scrolling
#! (sx, world) = jsWindow .# "scrollX" .? world
#! (sy, world) = jsWindow .# "scrollY" .? world
#! (sx, sy) = (jsValToReal` 0.0 sx, jsValToReal` 0.0 sy)
-> ((px (ax - (ix + sx)), px (ay - (iy + sy))), world)
// Update the view & the model
#! view = applyImgEventhandler (px (ax - (ix + sx)), px (ay - (iy + sy))) f cb_data view
#! view = applyImgEventhandler span f cb_data view
#! model = updModel model view
#! (jsView,world) = jsMakeCleanReference view me world
#! (jsModel,world)= jsMakeCleanReference model me world
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment