mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
EPUB CFI: Workaround webkit not reporting the boundingclientrect for an empty span that follows lots of whitespace correctly
This commit is contained in:
parent
3eb93282f6
commit
e33e5ede29
@ -482,7 +482,9 @@ class CanonicalFragmentIdentifier
|
||||
this.set_current_time(point.node, point.time)
|
||||
|
||||
if point.range != null
|
||||
# Character offset
|
||||
r = point.range
|
||||
[so, eo, sc, ec] = [r.startOffset, r.endOffset, r.startContainer, r.endContainer]
|
||||
node = r.startContainer
|
||||
ndoc = node.ownerDocument
|
||||
nwin = ndoc.defaultView
|
||||
@ -491,16 +493,19 @@ class CanonicalFragmentIdentifier
|
||||
r.surroundContents(span)
|
||||
span.scrollIntoView()
|
||||
fn = ->
|
||||
rect = span.getBoundingClientRect()
|
||||
x = (point.a*rect.left + (1-point.a)*rect.right)
|
||||
y = (rect.top + rect.bottom)/2
|
||||
[x, y] = viewport_to_document(x, y, ndoc)
|
||||
p = span.parentNode
|
||||
for node in span.childNodes
|
||||
span.removeChild(node)
|
||||
p.insertBefore(node, span)
|
||||
p.removeChild(span)
|
||||
p.normalize()
|
||||
r.setStart(sc, so)
|
||||
r.setEnd(ec, eo)
|
||||
|
||||
rect = r.getClientRects()[0]
|
||||
x = (point.a*rect.left + (1-point.a)*rect.right)
|
||||
y = (rect.top + rect.bottom)/2
|
||||
[x, y] = viewport_to_document(x, y, ndoc)
|
||||
if callback
|
||||
callback(x, y)
|
||||
else
|
||||
|
@ -66,8 +66,8 @@ window.onload = ->
|
||||
base = document.getElementById('first-h1').innerHTML
|
||||
document.title = base + ": " + window.current_cfi
|
||||
fn = () ->
|
||||
show_cfi()
|
||||
window_ypos(ypos)
|
||||
setTimeout(show_cfi, 1)
|
||||
setTimeout(fn, 100)
|
||||
null
|
||||
|
||||
|
@ -96,6 +96,9 @@
|
||||
demoralized by the charms of pleasure of the moment, so blinded
|
||||
by desire, that they cannot foresee</p>
|
||||
|
||||
<h2>Lots of collapsed whitespace</h2>
|
||||
<p>Try clicking the A character after the colon: A suffix</p>
|
||||
|
||||
<h2>Lots of nested tags</h2>
|
||||
<p>A <span>bunch of <span>nested<span> and</span> <span>sibling</span>
|
||||
tags, all </span> mixed together</span>. <span>Click all</span>
|
||||
|
Loading…
x
Reference in New Issue
Block a user