Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/epubview
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-04-09 14:55:18 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-04-09 14:55:18 (GMT)
commit31829913fe58cb95017f83a86aecaa05561ba611 (patch)
tree6c952275565abfef23ab5e92019df3258ed1ee09 /epubview
parenta4d8be9c984c86bf33bba75bd54a6422b341368d (diff)
Save and restore the page with epub files - SL #3413
When the user closed and reopened the activity, reading a epub file, the page was lost. The problem had two sources: The invisible webkit widget used to measure the document height, can add a scrollbar (randomly) then the inner width change, the text folw differently and the inner height change. This problem is solved setting document.documentElement.style.overflow = hidden in the widget when is used to measure. The second problem was, after the document was loaded and positioned the epubview tried to change the scroll position again. This patch include a minor change in readactivity.py, only to avoid call many times view.get_current_page. Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'epubview')
-rw-r--r--epubview/epubview.py17
-rw-r--r--epubview/jobs.py2
-rw-r--r--epubview/widgets.py9
3 files changed, 10 insertions, 18 deletions
diff --git a/epubview/epubview.py b/epubview/epubview.py
index 6df4830..ea52b5a 100644
--- a/epubview/epubview.py
+++ b/epubview/epubview.py
@@ -439,20 +439,6 @@ class _View(Gtk.HBox):
else:
self._scroll_page()
- base_pageno = self._paginator.get_base_pageno_for_file(filename)
- scrollval = self._v_vscrollbar.get_value()
- scroll_upper = self._v_vscrollbar.props.adjustment.props.upper
-
- if scroll_upper == 0: # This is a one page file
- pageno = base_pageno
- else:
- offset = (scrollval / scroll_upper) * \
- self._paginator.get_pagecount_for_file(filename)
- pageno = math.floor(base_pageno + offset)
-
- if pageno != self._loaded_page:
- self._on_page_changed(0, int(pageno))
-
# prepare text to speech
html_file = open(self._loaded_filename)
soup = BeautifulSoup.BeautifulSoup(html_file)
@@ -599,6 +585,7 @@ class _View(Gtk.HBox):
else:
self._view.load_uri('file://' + filename)
else:
+ self._loaded_page = pageno
self._scroll_page()
def _insert_js_reference(self, file_name, path):
@@ -658,8 +645,6 @@ class _View(Gtk.HBox):
self._scrollbar.set_increments(1.0, 1.0)
self._view.grab_focus()
self._view.grab_default()
- if self._loaded_page < 1:
- self._load_page(1)
def _destroy_cb(self, widget):
self._epub.close()
diff --git a/epubview/jobs.py b/epubview/jobs.py
index 31f15ad..368e210 100644
--- a/epubview/jobs.py
+++ b/epubview/jobs.py
@@ -116,7 +116,7 @@ class _JobPaginator(GObject.GObject):
"""
self._temp_win = Gtk.Window()
- self._temp_view = widgets._WebView()
+ self._temp_view = widgets._WebView(only_to_measure=True)
settings = self._temp_view.get_settings()
settings.props.default_font_family = 'DejaVu LGC Serif'
diff --git a/epubview/widgets.py b/epubview/widgets.py
index 39c52ce..0dd286b 100644
--- a/epubview/widgets.py
+++ b/epubview/widgets.py
@@ -2,17 +2,24 @@ from gi.repository import WebKit
class _WebView(WebKit.WebView):
- def __init__(self):
+ def __init__(self, only_to_measure=False):
WebKit.WebView.__init__(self)
+ self._only_to_measure = only_to_measure
def get_page_height(self):
'''
Gets height (in pixels) of loaded (X)HTML page.
This is done via javascript at the moment
'''
+ hide_scrollbar_js = ''
+ if self._only_to_measure:
+ hide_scrollbar_js = \
+ 'document.documentElement.style.overflow = "hidden";'
+
js = 'oldtitle=document.title;' + \
'if (document.body == null) {' + \
'document.title = 0} else {' + \
+ hide_scrollbar_js + \
'document.title=Math.max(document.body.scrollHeight, ' + \
'document.body.offsetHeight,document.documentElement.clientHeight,' + \
'document.documentElement.scrollHeight, ' + \