From dc4f4a581f2432681145e76da15476eb8b328adc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 3 Jul 2017 20:30:38 +0530 Subject: [PATCH] Browser viewer: Fix back/forward buttons not working correctly when clicking on links that lead to different internal files in the book. Fixes #1700004 [Content server: No way to return after footnote](https://bugs.launchpad.net/calibre/+bug/1700004) --- src/pyj/read_book/iframe.pyj | 2 +- src/pyj/read_book/view.pyj | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 37476b107d..c8f095b7ef 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -250,7 +250,7 @@ class IframeBoss: csi = current_spine_item() if csi.initial_position: ipos = csi.initial_position - self.replace_history_on_next_cfi_update = ipos.replace_history + self.replace_history_on_next_cfi_update = ipos.replace_history or False if ipos.type is 'frac': self.to_scroll_fraction(ipos.frac) elif ipos.type is 'anchor': diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 6c639f038c..81476a0203 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -101,6 +101,7 @@ class View: self.search_overlay = SearchOverlay(self) self.overlay = Overlay(self) self.src_doc = None + self.processing_spine_item_display = False self.iframe_ready = False self.pending_load = None self.encrypted_communications = False @@ -363,6 +364,7 @@ class View: def show_name(self, name, initial_position=None): if self.currently_showing.loading: return + self.processing_spine_item_display = False sd = get_session_data() settings={ 'margin_left': 0 if name is self.book.manifest.title_page_name else sd.get('margin_left'), @@ -393,7 +395,9 @@ class View: def goto_bookpos(self, bookpos): cfiname, internal_cfi = self.parse_cfi(bookpos, self.book) if cfiname and internal_cfi: - pos = {} + # replace_history has to be true here otherwise forward does not + # work after back, as back uses goto_bookpos + pos = {'replace_history': True} name = cfiname pos.type, pos.cfi = 'cfi', internal_cfi self.show_name(name, initial_position=pos) @@ -430,7 +434,8 @@ class View: self.goto_named_destination(toc_node.dest, toc_node.frag) def on_update_cfi(self, data): - if self.overlay.is_visible or self.search_overlay.is_visible: + overlay_shown = not self.processing_spine_item_display and self.overlay.is_visible + if overlay_shown or self.search_overlay.is_visible: # Chrome on Android stupidly resizes the viewport when the on # screen keyboard is displayed. This means that the push_state() # below causes the overlay to be closed, making it impossible to @@ -483,6 +488,7 @@ class View: # We cannot encrypt this message because the resource data contains # Blob objects which do not survive encryption self.encrypted_communications = False + self.processing_spine_item_display = True self.send_message('display', resource_data=resource_data, book=self.book, name=self.currently_showing.name, initial_position=self.currently_showing.initial_position, @@ -491,6 +497,7 @@ class View: self.encrypted_communications = True def on_content_loaded(self, data): + self.processing_spine_item_display = False self.hide_loading() frac = data.progress_frac or 0 self.update_read_percent(frac)