From 89639ac50928f085fffbe7604f3285374b0195f9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 10 Dec 2009 17:44:48 -0700 Subject: [PATCH] Workaround bug in Qt WebKit that causes innerHeight to sometimes erroneously return 0 --- Changelog.yaml | 2 +- src/calibre/gui2/viewer/documentview.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Changelog.yaml b/Changelog.yaml index 0a631f785a..62bbc38dce 100644 --- a/Changelog.yaml +++ b/Changelog.yaml @@ -20,7 +20,7 @@ description: > Now calibre will automatically check for updated versions of the recipes used to download the builting news sources. As a result, there is no need to upgrade calibre - just for recipe fixes. Note that you stil have to upgrade to get access to new + just for recipe fixes. Note that you still have to upgrade to get access to new news sources. type: major diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 1624c9148d..60807cc800 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -344,7 +344,10 @@ class Document(QWebPage): @property def height(self): - return self.javascript('document.body.offsetHeight', 'int') # contentsSize gives inaccurate results + ans = self.javascript('document.body.offsetHeight', 'int') # contentsSize gives inaccurate results + if ans == 0: + ans = self.mainFrame().contentsSize().height() + return ans @property def width(self): @@ -489,6 +492,7 @@ class DocumentView(QWebView): self.manager.load_started() self.loading_url = QUrl.fromLocalFile(path) #self.setContent(QByteArray(html.encode(path.encoding)), mt, QUrl.fromLocalFile(path)) + #open('/tmp/t.html', 'wb').write(html.encode(path.encoding)) self.setHtml(html, self.loading_url) self.turn_off_internal_scrollbars() @@ -585,8 +589,8 @@ class DocumentView(QWebView): else: self.document.set_bottom_padding(0) opos = self.document.ypos - lower_limit = opos + delta_y - max_y = self.document.height - window_height + lower_limit = opos + delta_y # Max value of top y co-ord after scrolling + max_y = self.document.height - window_height # The maximum possible top y co-ord if max_y < lower_limit: self.document.set_bottom_padding(lower_limit - max_y) max_y = self.document.height - window_height