Try to work out the selection from coordinates in handleMouseClickEvent.
If it doens't work fall back to window.getSelection()

This gives us better result as window.getSeletion() returns stale selection when clicking within already selected text

Also removed the window.SetTimeout bit as it only works under FireFox.
If a dom range ends just before the closing text:frame element, round it to the next
walkable position when converting it to cursor range.

Convert the following dom range to cursor range will have the same result
<text:frame><text:image/>|</text:frame>
<text:frame><text:image/></text:frame>|
Workaround a FireFox selection behaviour

In FireFox if an image has no text next to it, click on either side of the
image resulting the same selection get returned. anchorNode: image,
anchorOffset: 0. This cause the cursor remains to the left side of the
image even you click on the right side.