Viewer: Fix vertical margin at the top of the first page incorrect in a certain rare circumstance (first child of body being an empty paragraph). Fixes #1082640 (ebook-viewer: top line of the text is cut off when using two-paged mode)

This commit is contained in:
Kovid Goyal 2012-11-26 14:20:13 +05:30
parent 6e02f9a4a0
commit d29b097216
2 changed files with 12 additions and 0 deletions

Binary file not shown.

View File

@ -116,6 +116,18 @@ class PagedDisplay
# above the columns, which causes them to effectively be added to the # above the columns, which causes them to effectively be added to the
# page margins (the margin collapse algorithm) # page margins (the margin collapse algorithm)
bs.setProperty('-webkit-margin-collapse', 'separate') bs.setProperty('-webkit-margin-collapse', 'separate')
# Remove any webkit specified default margin from the first child of body
# Otherwise, you could end up with an effective negative margin, I dont
# understand exactly why, but see:
# https://bugs.launchpad.net/calibre/+bug/1082640 for an example
c = document.body.firstChild
count = 0
while c?.nodeType != 1 and count < 20
c = c?.nextSibling
count += 1
if c?.nodeType == 1
c.style.setProperty('-webkit-margin-before', '0')
bs.setProperty('overflow', 'visible') bs.setProperty('overflow', 'visible')
bs.setProperty('height', (window.innerHeight - this.margin_top - this.margin_bottom) + 'px') bs.setProperty('height', (window.innerHeight - this.margin_top - this.margin_bottom) + 'px')