Refactor fs code in the viewer

This commit is contained in:
Kovid Goyal 2012-07-24 11:56:41 +05:30
parent 07ce6e0a4f
commit 091164b307
3 changed files with 8 additions and 24 deletions

Binary file not shown.

View File

@ -73,7 +73,6 @@ class Document(QWebPage): # {{{
self.loaded_javascript = False self.loaded_javascript = False
self.js_loader = JavaScriptLoader( self.js_loader = JavaScriptLoader(
dynamic_coffeescript=self.debug_javascript) dynamic_coffeescript=self.debug_javascript)
self.initial_left_margin = self.initial_right_margin = u''
self.in_fullscreen_mode = False self.in_fullscreen_mode = False
self.setLinkDelegationPolicy(self.DelegateAllLinks) self.setLinkDelegationPolicy(self.DelegateAllLinks)
@ -187,10 +186,7 @@ class Document(QWebPage): # {{{
self.set_bottom_padding(0) self.set_bottom_padding(0)
self.fit_images() self.fit_images()
self.init_hyphenate() self.init_hyphenate()
self.initial_left_margin = unicode(self.javascript( self.javascript('full_screen.save_margins()')
'document.body.style.marginLeft').toString())
self.initial_right_margin = unicode(self.javascript(
'document.body.style.marginRight').toString())
if self.in_paged_mode: if self.in_paged_mode:
self.switch_to_paged_mode() self.switch_to_paged_mode()
if self.in_fullscreen_mode: if self.in_fullscreen_mode:
@ -257,27 +253,13 @@ class Document(QWebPage): # {{{
def switch_to_fullscreen_mode(self): def switch_to_fullscreen_mode(self):
self.in_fullscreen_mode = True self.in_fullscreen_mode = True
if self.in_paged_mode: self.javascript('full_screen.on(%d, %s)'%(self.max_fs_width,
self.javascript('paged_display.max_col_width = %d'%self.max_fs_width) 'true' if self.in_paged_mode else 'false'))
else:
self.javascript('''
var s = document.body.style;
s.maxWidth = "%dpx";
s.marginLeft = "auto";
s.marginRight = "auto";
'''%self.max_fs_width)
def switch_to_window_mode(self): def switch_to_window_mode(self):
self.in_fullscreen_mode = False self.in_fullscreen_mode = False
if self.in_paged_mode: self.javascript('full_screen.off(%s)'%('true' if self.in_paged_mode
self.javascript('paged_display.max_col_width = %d'%-1) else 'false'))
else:
self.javascript('''
var s = document.body.style;
s.maxWidth = "none";
s.marginLeft = "%s";
s.marginRight = "%s";
'''%(self.initial_left_margin, self.initial_right_margin))
@pyqtSignature("QString") @pyqtSignature("QString")
def debug(self, msg): def debug(self, msg):

View File

@ -32,10 +32,12 @@ class JavaScriptLoader(object):
'indexing':'ebooks.oeb.display.indexing', 'indexing':'ebooks.oeb.display.indexing',
'paged':'ebooks.oeb.display.paged', 'paged':'ebooks.oeb.display.paged',
'utils':'ebooks.oeb.display.utils', 'utils':'ebooks.oeb.display.utils',
'fs':'ebooks.oeb.display.full_screen',
} }
ORDER = ('jquery', 'jquery_scrollTo', 'bookmarks', 'referencing', 'images', ORDER = ('jquery', 'jquery_scrollTo', 'bookmarks', 'referencing', 'images',
'hyphenation', 'hyphenator', 'utils', 'cfi', 'indexing', 'paged') 'hyphenation', 'hyphenator', 'utils', 'cfi', 'indexing', 'paged',
'fs')
def __init__(self, dynamic_coffeescript=False): def __init__(self, dynamic_coffeescript=False):