mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Properly handle <iframe> tags
This commit is contained in:
parent
4f13ef6aaa
commit
004e7cfb68
@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
import os, math, re, glob
|
import os, math, re, glob
|
||||||
from PyQt4.Qt import QWidget, QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \
|
from PyQt4.Qt import QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \
|
||||||
QPainter, QPalette, QBrush, QFontDatabase, QDialog, \
|
QPainter, QPalette, QBrush, QFontDatabase, QDialog, \
|
||||||
QColor, QPoint, QImage, QRegion, QVariant, \
|
QColor, QPoint, QImage, QRegion, QVariant, \
|
||||||
QFont, QObject, QApplication, pyqtSignature
|
QFont, QObject, QApplication, pyqtSignature
|
||||||
@ -343,6 +343,8 @@ class Document(QWebPage):
|
|||||||
def width(self):
|
def width(self):
|
||||||
return self.mainFrame().contentsSize().width() # offsetWidth gives inaccurate results
|
return self.mainFrame().contentsSize().width() # offsetWidth gives inaccurate results
|
||||||
|
|
||||||
|
def load_finished(self, ok):
|
||||||
|
self.javascript('$("body").css("padding-bottom: 0px")')
|
||||||
|
|
||||||
class EntityDeclarationProcessor(object):
|
class EntityDeclarationProcessor(object):
|
||||||
|
|
||||||
@ -361,7 +363,7 @@ class DocumentView(QWebView):
|
|||||||
DISABLED_BRUSH = QBrush(Qt.lightGray, Qt.Dense5Pattern)
|
DISABLED_BRUSH = QBrush(Qt.lightGray, Qt.Dense5Pattern)
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
QWidget.__init__(self, *args)
|
QWebView.__init__(self, *args)
|
||||||
self.debug_javascript = False
|
self.debug_javascript = False
|
||||||
self.self_closing_pat = re.compile(r'<([a-z]+)\s+([^>]+)/>',
|
self.self_closing_pat = re.compile(r'<([a-z]+)\s+([^>]+)/>',
|
||||||
re.IGNORECASE)
|
re.IGNORECASE)
|
||||||
@ -374,8 +376,8 @@ class DocumentView(QWebView):
|
|||||||
self.manager = None
|
self.manager = None
|
||||||
self._reference_mode = False
|
self._reference_mode = False
|
||||||
self._ignore_scrollbar_signals = False
|
self._ignore_scrollbar_signals = False
|
||||||
self.connect(self.document, SIGNAL('loadStarted()'), self.load_started)
|
self.loading_url = None
|
||||||
self.connect(self.document, SIGNAL('loadFinished(bool)'), self.load_finished)
|
self.loadFinished.connect(self.load_finished)
|
||||||
self.connect(self.document, SIGNAL('linkClicked(QUrl)'), self.link_clicked)
|
self.connect(self.document, SIGNAL('linkClicked(QUrl)'), self.link_clicked)
|
||||||
self.connect(self.document, SIGNAL('linkHovered(QString,QString,QString)'), self.link_hovered)
|
self.connect(self.document, SIGNAL('linkHovered(QString,QString,QString)'), self.link_hovered)
|
||||||
self.connect(self.document, SIGNAL('selectionChanged()'), self.selection_changed)
|
self.connect(self.document, SIGNAL('selectionChanged()'), self.selection_changed)
|
||||||
@ -473,13 +475,12 @@ class DocumentView(QWebView):
|
|||||||
html = EntityDeclarationProcessor(html).processed_html
|
html = EntityDeclarationProcessor(html).processed_html
|
||||||
if 'xhtml' in mt:
|
if 'xhtml' in mt:
|
||||||
html = self.self_closing_pat.sub(self.self_closing_sub, html)
|
html = self.self_closing_pat.sub(self.self_closing_sub, html)
|
||||||
#self.setContent(QByteArray(html.encode(path.encoding)), mt, QUrl.fromLocalFile(path))
|
|
||||||
self.setHtml(html, QUrl.fromLocalFile(path))
|
|
||||||
self.turn_off_internal_scrollbars()
|
|
||||||
|
|
||||||
def load_started(self):
|
|
||||||
if self.manager is not None:
|
if self.manager is not None:
|
||||||
self.manager.load_started()
|
self.manager.load_started()
|
||||||
|
self.loading_url = QUrl.fromLocalFile(path)
|
||||||
|
#self.setContent(QByteArray(html.encode(path.encoding)), mt, QUrl.fromLocalFile(path))
|
||||||
|
self.setHtml(html, self.loading_url)
|
||||||
|
self.turn_off_internal_scrollbars()
|
||||||
|
|
||||||
def initialize_scrollbar(self):
|
def initialize_scrollbar(self):
|
||||||
if getattr(self, 'scrollbar', None) is not None:
|
if getattr(self, 'scrollbar', None) is not None:
|
||||||
@ -497,6 +498,11 @@ class DocumentView(QWebView):
|
|||||||
|
|
||||||
|
|
||||||
def load_finished(self, ok):
|
def load_finished(self, ok):
|
||||||
|
if self.loading_url is None:
|
||||||
|
# An <iframe> finished loading
|
||||||
|
return
|
||||||
|
self.loading_url = None
|
||||||
|
self.document.load_finished(ok)
|
||||||
self._size_hint = self.document.mainFrame().contentsSize()
|
self._size_hint = self.document.mainFrame().contentsSize()
|
||||||
scrolled = False
|
scrolled = False
|
||||||
if self.to_bottom:
|
if self.to_bottom:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user